@@ -187,20 +187,35 @@ export default class CSSSplitWebpackPlugin {
187
187
// Run on `emit` when user specifies the compiler phase
188
188
// Due to the incorrect css split + optimization behavior
189
189
// 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
+ }
193
199
} else {
194
200
// Only run on `this-compilation` to avoid injecting the plugin into
195
201
// 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
+ } ) ;
203
217
} ) ;
218
+ }
204
219
}
205
220
}
206
221
}
0 commit comments