Skip to content

Commit 123eb80

Browse files
committed
feat: add support for old webpack
1 parent 0fb336f commit 123eb80

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/index.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,35 @@ export default class CSSSplitWebpackPlugin {
187187
// Run on `emit` when user specifies the compiler phase
188188
// Due to the incorrect css split + optimization behavior
189189
// Expected: css split should happen after optimization
190-
compiler.hooks.emit.tapAsync('css-split-emit', (compilation, done) => {
191-
return this.chunksMapping(compilation, compilation.chunks, done);
192-
});
190+
if (compiler.hooks) {
191+
compiler.hooks.emit.tapAsync('css-split-emit', (compilation, done) => {
192+
return this.chunksMapping(compilation, compilation.chunks, done);
193+
});
194+
} else {
195+
compiler.plugin('emit', (compilation, done) => {
196+
return this.chunksMapping(compilation, compilation.chunks, done);
197+
});
198+
}
193199
} else {
194200
// Only run on `this-compilation` to avoid injecting the plugin into
195201
// sub-compilers as happens when using the `extract-text-webpack-plugin`.
196-
compiler.hooks.thisCompilation.tap('css-split-this-compilation',
197-
(compilation) => {
198-
compilation.hooks.optimizeChunkAssets.tapAsync(
199-
'css-split-optimize-chunk-assets',
200-
(chunks, done) => {
201-
return this.chunksMapping(compilation, chunks, done);
202-
});
202+
// eslint-disable-next-line no-lonely-if
203+
if (compiler.hooks) {
204+
compiler.hooks.thisCompilation.tap('css-split-this-compilation',
205+
(compilation) => {
206+
compilation.hooks.optimizeChunkAssets.tapAsync(
207+
'css-split-optimize-chunk-assets',
208+
(chunks, done) => {
209+
return this.chunksMapping(compilation, chunks, done);
210+
});
211+
});
212+
} else {
213+
compiler.plugin('this-compilation', (compilation) => {
214+
compilation.plugin('optimize-chunk-assets', (chunks, done) => {
215+
return this.chunksMapping(compilation, chunks, done);
216+
});
203217
});
218+
}
204219
}
205220
}
206221
}

0 commit comments

Comments
 (0)