1
1
import * as webpack from 'webpack' ;
2
2
import * as ConcatSource from 'webpack-sources' ;
3
+ import * as path from 'path' ;
3
4
import * as _ from 'lodash' ;
4
5
import { pri } from '../node' ;
5
6
@@ -14,16 +15,20 @@ export class WrapContent {
14
15
}
15
16
16
17
public apply ( compiler : webpack . Compiler ) {
17
- compiler . plugin ( 'compilation ', compilation => {
18
- compilation . plugin ( 'optimize-chunk-assets ', ( chunks : any [ ] , done : any ) => {
18
+ compiler . hooks . compilation . tap ( 'WrapContent ', compilation => {
19
+ compilation . hooks . optimizeChunkAssets . tapAsync ( 'WrapContent ', ( chunks , done ) => {
19
20
chunks . forEach ( chunk => {
20
- chunk . files . forEach ( ( fileName : string ) => {
21
+ chunk . files . forEach ( fileName => {
21
22
// Ignore workers
22
23
if ( fileName . indexOf ( 'worker.js' ) > - 1 ) {
23
24
return ;
24
25
}
25
26
26
- if ( chunk . name === 'main' || _ . has ( pri . sourceConfig . entries , chunk . name ) ) {
27
+ if (
28
+ chunk . name === 'main' ||
29
+ chunk . name === path . basename ( pri . sourceConfig . outFileName , '.js' ) ||
30
+ _ . has ( pri . sourceConfig . entries , chunk . name )
31
+ ) {
27
32
compilation . assets [ fileName ] = new ConcatSource . ConcatSource (
28
33
this . header ,
29
34
compilation . assets [ fileName ] ,
0 commit comments