next: 6.0.1-canary.2
just change a little code in page, the yarn build .next/static/commons/main-xxxx.js always change. How to avoid it?
like this, modify some text in page/page2.js:
<div>Welcome to Page2 </div> to <div>Welcome to Page2 ABC </div>
the .next/static/commons/main-xxxx.js should not change when yarn build
but the main-6974e8617b50c9d0b1bf.js changed to main-515736f6b9f5ff2e32e1.js
Does anyone know how to keep generated main-xxxx.js not change when dependent library has no change?
I already try to rewrite the next.config.js only process node_modules file, but no luck:
const path = require('path')
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
for (plugin of config.plugins) {
if (plugin['constructor']['name'] === 'CommonsChunkPlugin') {
plugin.minChunks = function (module, count) {
var needChunk = (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, './node_modules')
) === 0
)
if (needChunk) {
console.log("needChunk = ", module.resource)
}
return needChunk
}
break;
}
}
return config
},
}
I'm not sure what you're asking. Please follow the issue template and provide a clear description of the issue you're having.
The fact that the chunk hash changes means there's something different in the chunk.
@timneutkens
The fact that the chunk hash changes means there's something different in the chunk.
Do you know what .next/static/commons/main-xxxx.js design for?
Just follow this:
1, Populate
./pages/index.jsinside your project:export default () => <div>Welcome to next.js!</div>
2, Runyarn build, look the folder.next/static/commons/
3, Change./pages/index.jscontent :export default () => <div>Foo</div>
4, Runyarn buildagain, look the folder.next/static/commons/
5, Think, why there are twomain-xxxx.jsinside.next/static/commons/??? Is it correct?.next\dist\bundles\pages\index.jsalready re-compiled, Why the commonmain-xxxx.jsstill re-create?
I guess the "commons" is not stand for COMMON. We need a "vendor-xxx.js" only include "node_modules" code, then the "main-xxx.js" will be much smaller.
For now, any little change lead the .next/static/commons/main-xxxx.js 200+ KB file to re-create new one, doesn't make any sense.
any follow up on this? In my case, the main-xxxx.js's hash changes every time I build, no new npm pkgs are installed, and no code change as well
I wanna get like this .next/static/commons/main.js instead of .next/static/commons/main-xxxx.js
how to operate ?
I resolve it:
config.plugins = config.plugins.map(plugin => {
if (plugin.constructor.name === 'CommonsChunkPlugin') {
plugin = Object.assign(plugin, {
filenameTemplate: `static/commons/main-${dayjs().format('YYYYMMDD')}.js`,
})
}
return plugin
})
This won't work with Next.js 7, and Next.js 7 implements records.json so hashes should be more stable now.
Most helpful comment
I wanna get like this
.next/static/commons/main.jsinstead of.next/static/commons/main-xxxx.jshow to operate ?