11import * as webpack from 'webpack' ;
22import * as ConcatSource from 'webpack-sources' ;
3+ import * as path from 'path' ;
34import * as _ from 'lodash' ;
45import { pri } from '../node' ;
56
@@ -14,16 +15,20 @@ export class WrapContent {
1415 }
1516
1617 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 ) => {
1920 chunks . forEach ( chunk => {
20- chunk . files . forEach ( ( fileName : string ) => {
21+ chunk . files . forEach ( fileName => {
2122 // Ignore workers
2223 if ( fileName . indexOf ( 'worker.js' ) > - 1 ) {
2324 return ;
2425 }
2526
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+ ) {
2732 compilation . assets [ fileName ] = new ConcatSource . ConcatSource (
2833 this . header ,
2934 compilation . assets [ fileName ] ,
0 commit comments