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 a445791

Browse files
add support for html webpack plugin beta
1 parent 8e08591 commit a445791

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

‎index.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
'use strict';
2+
let js = [];
3+
let run = 0;
4+
25
function HtmlWebpackMultiBuildPlugin(options) {
36
this.options = options;
4-
this.js = [];
57
}
68

79
HtmlWebpackMultiBuildPlugin.prototype = {
810
apply: function(compiler) {
911
if (compiler.hooks) {
1012
// webpack 4 support
1113
compiler.hooks.compilation.tap('HtmlWebpackMultiBuildPlugin', compilation => {
12-
compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration.tapAsync(
14+
if (compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration) {
15+
compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration.tapAsync(
1316
'HtmlWebpackMultiBuildPlugin',
1417
this.beforeHtmlGeneration.bind(this),
15-
);
18+
);
19+
} else {
20+
var HtmlWebpackPlugin = require('html-webpack-plugin');
21+
var hooks = HtmlWebpackPlugin.getHooks(compilation);
22+
hooks.beforeAssetTagGeneration.tapAsync(
23+
'HtmlWebpackMultiBuildPlugin',
24+
this.beforeHtmlGeneration.bind(this),
25+
);
26+
}
1627
});
1728
} else {
1829
compiler.plugin('compilation', compilation => {
@@ -22,10 +33,14 @@ HtmlWebpackMultiBuildPlugin.prototype = {
2233
},
2334

2435
beforeHtmlGeneration: function(data, cb) {
25-
this.js = this.js.concat(data.assets.js);
26-
data.assets.js = this.js;
27-
data.plugin.options.modernScripts = this.js.filter((value) => value.indexOf('legacy') === -1);
28-
data.plugin.options.legacyScripts = this.js.filter((value) => value.indexOf('legacy') > 0);
36+
++run;
37+
js = js.concat(data.assets.js);
38+
data.assets.js = js;
39+
if (run === 2) {
40+
data.plugin.options.modernScripts = js.filter((value) => value.indexOf('legacy') === -1);
41+
data.plugin.options.legacyScripts = js.filter((value) => value.indexOf('legacy') > 0);
42+
}
43+
2944
cb(null, data);
3045
},
3146
};

0 commit comments

Comments
(0)

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