Skip to content

Commit 7dffb13

Browse files
author
chengyu.chengyulia
committed
fix: WrapContent plugin
1 parent 39c6c0c commit 7dffb13

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/utils/webpack-plugin-wrap-content.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as webpack from 'webpack';
22
import * as ConcatSource from 'webpack-sources';
3+
import * as path from 'path';
34
import * as _ from 'lodash';
45
import { 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

Comments
 (0)