Created
April 18, 2022 21:35
-
-
Save joeypy/d65c462f79b47d24acf96f79a32fa889 to your computer and use it in GitHub Desktop.
NextJS export cache issue fix. Update cache on every build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* the trick is to build unique build ID on every build and add it to static files on build time. | |
* This way the name and URL of static files will change on every build. | |
*/ | |
/* eslint-disable @typescript-eslint/no-var-requires */ | |
const path = require('path'); | |
// Used to set folders as alias to directly use in nextjs | |
const nextConfiguration = ({ | |
webpack: (config, { buildId, dev }) => { | |
const newConfig = config; | |
if (!dev && newConfig.output.filename.startsWith('static')) { | |
newConfig.output.filename = newConfig.output.filename.replace('[name]', `[name]-${buildId}`); | |
newConfig.output.chunkFilename = newConfig.output.chunkFilename.replace('[name]', `[name]-${buildId}`); | |
} | |
return newConfig; | |
}, | |
generateBuildId: async () => { | |
const timestamp = Math.floor(Date.now() / 1000); | |
return `build-${timestamp}`; | |
}, | |
}); | |
module.exports = nextConfiguration; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment