Skip to content

Commit 79f4983

Browse files
committed
Fixed source concatenation not working in webpack 4.
1 parent 52c45fe commit 79f4983

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

wrapper-webpack-plugin.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class WrapperPlugin {
2626
}
2727

2828
apply(compiler) {
29-
const ConcatSource = compiler.webpack.sources.ConcatSource;
29+
const ConcatSource = getSourceConcatenator(compiler);
3030

3131
const header = this.header;
3232
const footer = this.footer;
@@ -50,9 +50,9 @@ class WrapperPlugin {
5050
const footerContent = (typeof footer === 'function') ? footer(fileName, chunkHash) : footer;
5151

5252
compilation.assets[fileName] = new ConcatSource(
53-
String(headerContent),
54-
compilation.assets[fileName],
55-
String(footerContent),
53+
String(headerContent),
54+
compilation.assets[fileName],
55+
String(footerContent),
5656
);
5757
}
5858

@@ -73,3 +73,13 @@ class WrapperPlugin {
7373
}
7474

7575
module.exports = WrapperPlugin;
76+
77+
function getSourceConcatenator(compiler) {
78+
const webpack = compiler.webpack;
79+
if (webpack) {
80+
// webpack v5
81+
return webpack.sources.ConcatSource;
82+
}
83+
// webpack v4
84+
return require("webpack-sources").ConcatSource;
85+
}

0 commit comments

Comments
 (0)