@@ -5,6 +5,18 @@ const resolve = function (_path) {
5
5
return path . resolve ( __dirname , _path )
6
6
}
7
7
const cfg = require ( './webpack.cfg' )
8
+
9
+ // 判断当前页面是否包含CommonCssChunk
10
+ function getCommonCssChunk ( chunkName ) {
11
+ if ( ! cfg . commonCss ) return [ ]
12
+ // 无commonCss.exclude,所有页面包含
13
+ if ( ! cfg . commonCss . exclude ) return 'common_css'
14
+ // 有commonCss.exclude,不包含在该数组的页面引用
15
+ if ( cfg . commonCss . exclude && ! cfg . commonCss . exclude . includes ( chunkName ) ) return 'common_css'
16
+ // 其他
17
+ return [ ]
18
+ }
19
+
8
20
let until = {
9
21
resolve,
10
22
getFileList ( targetPath ) {
@@ -64,13 +76,13 @@ let until = {
64
76
var reg = / \. [ ^ . ] + $ /
65
77
if ( reg . test ( file . filename ) ) {
66
78
chunkName = file . filename . replace ( reg , '' )
67
- console . log ( '.' + file . filepath . replace ( targetPath , '' ) . replace ( reg , '.html' ) )
79
+ console . log ( '.' + file . filepath . replace ( targetPath , '' ) . replace ( reg , '.html' ) )
68
80
HtmlWebpackPlugins . push (
69
81
new HtmlWebpackPlugin ( {
70
- baseTagUrl :'../' ,
82
+ baseTagUrl : '../' ,
71
83
template : file . filepath ,
72
- filename :'.' + file . filepath . replace ( targetPath , '' ) . replace ( reg , '.html' ) ,
73
- chunks : [ chunkName ] . concat ( argv . mode === 'production' ? [ 'vendor' , 'commons' , 'manifest' ] : [ ] ) ,
84
+ filename : '.' + file . filepath . replace ( targetPath , '' ) . replace ( reg , '.html' ) ,
85
+ chunks : [ chunkName ] . concat ( getCommonCssChunk ( chunkName ) ) . concat ( argv . mode === 'production' ? [ 'vendor' , 'commons' , 'manifest' ] : [ ] ) ,
74
86
inject : true ,
75
87
minify : argv . mode !== 'production' ? undefined : {
76
88
removeComments : true ,
0 commit comments