Skip to content

Commit a426b8c

Browse files
committed
Always used named chunks to avoid caching problems
1 parent 9a4030c commit a426b8c

File tree

2 files changed

+58
-12
lines changed

2 files changed

+58
-12
lines changed

lib/config-generator.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ class ConfigGenerator {
403403
// which can be useful for debugging, especially with HMR
404404
optimization.namedModules = true;
405405
}
406+
// https://github.com/webpack/webpack/issues/8354
407+
// likely can be removed in Webpack 5
408+
// https://github.com/webpack/webpack/pull/8374
409+
optimization.chunkIds = 'named';
406410

407411
let splitChunks = {
408412
chunks: this.webpackConfig.shouldSplitEntryChunks ? 'all' : 'async'

test/functional.js

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,22 @@ describe('Functional tests using webpack', function() {
318318
});
319319
});
320320

321+
it('.mjs files are supported natively', (done) => {
322+
const config = createWebpackConfig('web/build', 'dev');
323+
config.addEntry('main', './js/hello_world');
324+
config.setPublicPath('/build');
325+
326+
testSetup.runWebpack(config, (webpackAssert) => {
327+
// check that main.js has the correct contents
328+
webpackAssert.assertOutputFileContains(
329+
'main.js',
330+
'Hello World!'
331+
);
332+
333+
done();
334+
});
335+
});
336+
321337
describe('addStyleEntry .js files are removed', () => {
322338
it('Without versioning', (done) => {
323339
const config = createWebpackConfig('web', 'dev');
@@ -1628,7 +1644,7 @@ module.exports = {
16281644
});
16291645
});
16301646

1631-
describe('entrypoints.json', () => {
1647+
describe('entrypoints.json & splitChunks()', () => {
16321648
it('Use "all" splitChunks & look at entrypoints.json', (done) => {
16331649
const config = createWebpackConfig('web/build', 'dev');
16341650
config.addEntry('main', ['./css/roboto_font.css', './js/no_require', 'vue']);
@@ -1809,19 +1825,45 @@ module.exports = {
18091825
});
18101826
});
18111827

1812-
it('.mjs files are supported natively', (done) => {
1813-
const config = createWebpackConfig('web/build', 'dev');
1814-
config.addEntry('main', './js/hello_world');
1815-
config.setPublicPath('/build');
1828+
it('Make sure chunkIds do not change between builds', (done) => {
1829+
// https://github.com/symfony/webpack-encore/issues/461
1830+
const createSimilarConfig = function(includeExtraEntry) {
1831+
const config = createWebpackConfig('web/build', 'production');
1832+
config.addEntry('main1', './js/code_splitting');
1833+
if (includeExtraEntry) {
1834+
config.addEntry('main2', './js/eslint');
1835+
}
1836+
config.addEntry('main3', './js/no_require');
1837+
config.setPublicPath('/build');
18161838

1817-
testSetup.runWebpack(config, (webpackAssert) => {
1818-
// check that main.js has the correct contents
1819-
webpackAssert.assertOutputFileContains(
1820-
'main.js',
1821-
'Hello World!'
1822-
);
1839+
return config;
1840+
};
18231841

1824-
done();
1842+
const getMain3Contents = function(config) {
1843+
const fullPath = path.join(config.outputPath, 'main3.js');
1844+
1845+
if (!fs.existsSync(fullPath)) {
1846+
throw new Error('Output file "main3.js" does not exist.');
1847+
}
1848+
1849+
return fs.readFileSync(fullPath, 'utf8');
1850+
};
1851+
1852+
const configA = createSimilarConfig(false);
1853+
const configB = createSimilarConfig(true);
1854+
1855+
testSetup.runWebpack(configA, () => {
1856+
const main3Contents = getMain3Contents(configA);
1857+
1858+
testSetup.runWebpack(configB, () => {
1859+
const finalMain3Contents = getMain3Contents(configB);
1860+
1861+
if (finalMain3Contents !== main3Contents) {
1862+
throw new Error(`Contents after first compile do not match after second compile: \n\n ${main3Contents} \n\n versus \n\n ${finalMain3Contents} \n`);
1863+
}
1864+
1865+
done();
1866+
});
18251867
});
18261868
});
18271869
});

0 commit comments

Comments
 (0)