@@ -5,6 +5,18 @@ const resolve = function (_path) {
55 return path . resolve ( __dirname , _path )
66}
77const 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+
820let until = {
921 resolve,
1022 getFileList ( targetPath ) {
@@ -64,13 +76,13 @@ let until = {
6476 var reg = / \. [ ^ . ] + $ /
6577 if ( reg . test ( file . filename ) ) {
6678 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' ) )
6880 HtmlWebpackPlugins . push (
6981 new HtmlWebpackPlugin ( {
70- baseTagUrl :'../' ,
82+ baseTagUrl : '../' ,
7183 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' ] : [ ] ) ,
7486 inject : true ,
7587 minify : argv . mode !== 'production' ? undefined : {
7688 removeComments : true ,
0 commit comments