Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Commit 7406af9

Browse files
authored
Clear old entry files
This is a potential solution to #3, obviously can use improvements, like support for [hash:10] (any custom hash length number), options which differ from [hash] like chunkhash etc. I'm not entirely convinced this would be the way to go, let me know what you think? If you believe this could potentially fix things we can expand it, for me this is working rather nicely (I was debugging this.js to see if it clears old files).
1 parent 8e08591 commit 7406af9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function HtmlWebpackMultiBuildPlugin(options) {
66

77
HtmlWebpackMultiBuildPlugin.prototype = {
88
apply: function(compiler) {
9+
this.createOutputRegexes(compiler.options);
10+
911
if (compiler.hooks) {
1012
// webpack 4 support
1113
compiler.hooks.compilation.tap('HtmlWebpackMultiBuildPlugin', compilation => {
@@ -28,6 +30,33 @@ HtmlWebpackMultiBuildPlugin.prototype = {
2830
data.plugin.options.legacyScripts = this.js.filter((value) => value.indexOf('legacy') > 0);
2931
cb(null, data);
3032
},
33+
createOutputRegexes: function(options) {
34+
if (options.output && options.output.filename) {
35+
// default webpack entry
36+
let entry = ['main'];
37+
if (options.entry) {
38+
// when object is provided we have custom entry names
39+
if (typeof options.entry === 'object') {
40+
entry = Object.keys(options.entry);
41+
}
42+
}
43+
entry.forEach(e => {
44+
const outFilePathForEntry = options.output.filename.replace('[name]', e);
45+
this.outputFileNameRegex.push(new RegExp(outFilePathForEntry.replace(['[hash]'], '[\\w\\d]{20}')));
46+
});
47+
}
48+
},
49+
clearOldScripts: function(data) {
50+
this.clearOldScripts(data);
51+
this.outputFileNameRegex.forEach(r => {
52+
data.assets.js.forEach(a => {
53+
// we have one of our entries
54+
if (r.test(a)) {
55+
this.js = this.js.filter(j => !r.test(j));
56+
}
57+
});
58+
});
59+
},
3160
};
3261

3362
module.exports = HtmlWebpackMultiBuildPlugin;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /