1
- const ExtractCssChunks = require ( 'extract-css-chunks-webpack-plugin' ) ;
2
- const findUp = require ( 'find-up' ) ;
3
- const OptimizeCssAssetsWebpackPlugin = require ( 'optimize-css-assets-webpack-plugin' ) ;
1
+ const ExtractCssChunks = require ( 'extract-css-chunks-webpack-plugin' )
2
+ const findUp = require ( 'find-up' )
3
+ const OptimizeCssAssetsWebpackPlugin = require ( 'optimize-css-assets-webpack-plugin' )
4
4
5
- const fileExtensions = new Set ( ) ;
6
- let extractCssInitialized = false ;
5
+ const fileExtensions = new Set ( )
6
+ let extractCssInitialized = false
7
7
8
8
module . exports = (
9
9
config ,
@@ -19,7 +19,7 @@ module.exports = (
19
19
) => {
20
20
// We have to keep a list of extensions for the splitchunk config
21
21
for ( const extension of extensions ) {
22
- fileExtensions . add ( extension ) ;
22
+ fileExtensions . add ( extension )
23
23
}
24
24
25
25
if ( ! isServer && config . optimization . splitChunks . cacheGroups ) {
@@ -28,58 +28,55 @@ module.exports = (
28
28
test : new RegExp ( `\\.+(${ [ ...fileExtensions ] . join ( '|' ) } )$` ) ,
29
29
chunks : 'all' ,
30
30
enforce : true
31
- } ;
31
+ }
32
32
}
33
33
34
34
if ( ! isServer && ! extractCssInitialized ) {
35
35
config . plugins . push (
36
36
new ExtractCssChunks ( {
37
37
// Options similar to the same options in webpackOptions.output
38
38
// both options are optional
39
- filename : dev
40
- ? 'static/chunks/[name].css'
41
- : 'static/chunks/[name].[contenthash:8].css' ,
42
- chunkFilename : dev
43
- ? 'static/chunks/[name].chunk.css'
44
- : 'static/chunks/[name].[contenthash:8].chunk.css' ,
39
+ filename : 'static/chunks/[name].[contenthash:8].css' ,
40
+ chunkFilename : 'static/chunks/[name].[contenthash:8].chunk.css' ,
41
+ orderWarning : true ,
45
42
hot : dev
46
43
} )
47
- ) ;
48
- extractCssInitialized = true ;
44
+ )
45
+ extractCssInitialized = true
49
46
}
50
47
51
48
if ( ! dev ) {
52
49
if ( ! Array . isArray ( config . optimization . minimizer ) ) {
53
- config . optimization . minimizer = [ ] ;
50
+ config . optimization . minimizer = [ ]
54
51
}
55
52
config . optimization . minimizer . push (
56
53
new OptimizeCssAssetsWebpackPlugin ( {
57
54
cssProcessorOptions : {
58
55
discardComments : { removeAll : true }
59
56
}
60
57
} )
61
- ) ;
58
+ )
62
59
}
63
60
64
61
const postcssConfig = findUp . sync ( 'postcss.config.js' , {
65
62
cwd : config . context
66
- } ) ;
67
- let postcssLoader ;
63
+ } )
64
+ let postcssLoader
68
65
69
66
if ( postcssConfig ) {
70
67
// Copy the postcss-loader config options first.
71
68
const postcssOptionsConfig = Object . assign (
72
69
{ } ,
73
70
postcssLoaderOptions . config ,
74
71
{ path : postcssConfig }
75
- ) ;
72
+ )
76
73
77
74
postcssLoader = {
78
75
loader : 'postcss-loader' ,
79
76
options : Object . assign ( { } , postcssLoaderOptions , {
80
77
config : postcssOptionsConfig
81
78
} )
82
- } ;
79
+ }
83
80
}
84
81
85
82
const cssLoader = {
@@ -97,16 +94,16 @@ module.exports = (
97
94
} ,
98
95
cssLoaderOptions
99
96
)
100
- } ;
97
+ }
101
98
102
99
// When not using css modules we don't transpile on the server
103
100
if ( isServer && ! cssLoader . options . modules ) {
104
- return [ 'ignore-loader' ] ;
101
+ return [ 'ignore-loader' ]
105
102
}
106
103
107
104
// When on the server and using css modules we transpile the css
108
105
if ( isServer && cssLoader . options . modules ) {
109
- return [ cssLoader , postcssLoader , ...loaders ] . filter ( Boolean ) ;
106
+ return [ cssLoader , postcssLoader , ...loaders ] . filter ( Boolean )
110
107
}
111
108
112
109
return [
@@ -115,5 +112,5 @@ module.exports = (
115
112
cssLoader ,
116
113
postcssLoader ,
117
114
...loaders
118
- ] . filter ( Boolean ) ;
119
- } ;
115
+ ] . filter ( Boolean )
116
+ }
0 commit comments