Skip to content

Commit 9962b7f

Browse files
committed
bug #901 Working around missing manifest.json bug (weaverryan)
This PR was merged into the main branch. Discussion ---------- Working around missing manifest.json bug This fixes the 2nd part of #893 - #893 (comment) On Webpack 5, there is some miscommunication between the CleanWebpackPlugin and the WebpackManifestPlugin when using `dev-server`. The `WebpackManifestPlugin` *does* emit the physical `manifest.json` file, but CleanWebpackPlugin then deletes it. CleanWebpackPlugin should just remove files *before* we start, and not delete anything that's emitted. I'm not sure which plugin has the bug. But, the work around is quite clean. Commits ------- a4a6665 Working around missing manifest.json bug
2 parents 2bc8980 + a4a6665 commit 9962b7f

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,11 +1421,11 @@ class Encore {
14211421
* // common values: asset, asset/resource, asset/inline
14221422
* // Using "asset" will allow smaller images to be "inlined"
14231423
* // instead of copied.
1424-
* // javascript/auto caan be used to disable asset images (see next example)
1424+
* // javascript/auto can be used to disable asset images (see next example)
14251425
* type: 'asset/resource',
14261426
*
14271427
* // applicable when for "type: asset": files smaller than this
1428-
* // size will be "inlined" into CSS, larer files will be extracted
1428+
* // size will be "inlined" into CSS, larger files will be extracted
14291429
* // into independent files
14301430
* maxSize: 4 * 1024, // 4 kb
14311431
*

lib/plugins/clean.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ module.exports = function(plugins, webpackConfig) {
2727
return;
2828
}
2929

30+
const cleanOnceBeforeBuildPatterns = webpackConfig.cleanWebpackPluginPaths;
31+
// works around a bug where manifest.json is emitted when
32+
// using dev-server... but then CleanWebpackPlugin deletes it
33+
cleanOnceBeforeBuildPatterns.push('!manifest.json');
34+
3035
const cleanWebpackPluginOptions = {
3136
verbose: false,
3237
cleanOnceBeforeBuildPatterns: webpackConfig.cleanWebpackPluginPaths,

test/plugins/clean.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('plugins/clean', () => {
4141
cleanPluginUtil(plugins, config);
4242
expect(plugins.length).to.equal(1);
4343
expect(plugins[0].plugin).to.be.instanceof(CleanWebpackPlugin);
44-
expect(plugins[0].plugin.cleanOnceBeforeBuildPatterns).to.deep.equal(['**/*']);
44+
expect(plugins[0].plugin.cleanOnceBeforeBuildPatterns).to.deep.equal(['**/*', '!manifest.json']);
4545
expect(plugins[0].plugin.dry).to.equal(false);
4646
});
4747

@@ -56,7 +56,7 @@ describe('plugins/clean', () => {
5656
cleanPluginUtil(plugins, config);
5757
expect(plugins.length).to.equal(1);
5858
expect(plugins[0].plugin).to.be.instanceof(CleanWebpackPlugin);
59-
expect(plugins[0].plugin.cleanOnceBeforeBuildPatterns).to.deep.equal(['**/*.js', '**/*.css']);
59+
expect(plugins[0].plugin.cleanOnceBeforeBuildPatterns).to.deep.equal(['**/*.js', '**/*.css', '!manifest.json']);
6060
expect(plugins[0].plugin.dry).to.equal(true);
6161
});
6262

0 commit comments

Comments
 (0)