@@ -57,12 +57,12 @@ const findOptions = (config, lang, _loader, index) => {
57
57
}
58
58
59
59
test ( 'default loaders' , ( ) => {
60
- const config = genConfig ( { postcss : { } } )
60
+ const config = genConfig ( )
61
61
62
62
LANGS . forEach ( lang => {
63
63
const loader = lang === 'css' ? [ ] : LOADERS [ lang ]
64
64
expect ( findLoaders ( config , lang ) ) . toEqual ( [ 'vue-style' , 'css' , 'postcss' ] . concat ( loader ) )
65
- expect ( findOptions ( config , lang , 'postcss' ) . plugins ) . toBeFalsy ( )
65
+ expect ( findOptions ( config , lang , 'postcss' ) . plugins ) . toEqual ( [ require ( 'autoprefixer' ) ] )
66
66
// assert css-loader options
67
67
expect ( findOptions ( config , lang , 'css' ) ) . toEqual ( {
68
68
sourceMap : false ,
@@ -79,11 +79,25 @@ test('default loaders', () => {
79
79
} )
80
80
81
81
test ( 'production defaults' , ( ) => {
82
- const config = genConfig ( { postcss : { } } , 'production' )
82
+ const config = genConfig ( { } , 'production' )
83
83
LANGS . forEach ( lang => {
84
84
const loader = lang === 'css' ? [ ] : LOADERS [ lang ]
85
85
expect ( findLoaders ( config , lang ) ) . toEqual ( [ extractLoaderPath , 'css' , 'postcss' ] . concat ( loader ) )
86
+ expect ( findOptions ( config , lang , 'postcss' ) . plugins ) . toEqual ( [ require ( 'autoprefixer' ) ] )
87
+ expect ( findOptions ( config , lang , 'css' ) ) . toEqual ( {
88
+ sourceMap : false ,
89
+ importLoaders : 2
90
+ } )
91
+ } )
92
+ } )
93
+
94
+ test ( 'override postcss config' , ( ) => {
95
+ const config = genConfig ( { postcss : { } } )
96
+ LANGS . forEach ( lang => {
97
+ const loader = lang === 'css' ? [ ] : LOADERS [ lang ]
98
+ expect ( findLoaders ( config , lang ) ) . toEqual ( [ 'vue-style' , 'css' , 'postcss' ] . concat ( loader ) )
86
99
expect ( findOptions ( config , lang , 'postcss' ) . plugins ) . toBeFalsy ( )
100
+ // assert css-loader options
87
101
expect ( findOptions ( config , lang , 'css' ) ) . toEqual ( {
88
102
sourceMap : false ,
89
103
importLoaders : 2
@@ -101,7 +115,7 @@ test('CSS Modules rules', () => {
101
115
} )
102
116
LANGS . forEach ( lang => {
103
117
const expected = {
104
- importLoaders : 1 , // no postcss-loader
118
+ importLoaders : 2 , // with postcss-loader
105
119
sourceMap : false ,
106
120
modules : {
107
121
localIdentName : `[name]_[local]_[hash:base64:5]`
@@ -140,7 +154,7 @@ test('Customized CSS Modules rules', () => {
140
154
141
155
LANGS . forEach ( lang => {
142
156
const expected = {
143
- importLoaders : 1 , // no postcss-loader
157
+ importLoaders : 2 , // with postcss-loader
144
158
sourceMap : false ,
145
159
modules : {
146
160
localIdentName : `[folder]-[name]-[local][emoji]`
@@ -174,7 +188,7 @@ test('deprecate `css.modules` option', () => {
174
188
175
189
LANGS . forEach ( lang => {
176
190
const expected = {
177
- importLoaders : 1 , // no postcss-loader
191
+ importLoaders : 2 , // with postcss-loader
178
192
sourceMap : false ,
179
193
modules : {
180
194
localIdentName : `[folder]-[name]-[local][emoji]`
@@ -211,7 +225,7 @@ test('favor `css.requireModuleExtension` over `css.modules`', () => {
211
225
212
226
LANGS . forEach ( lang => {
213
227
const expected = {
214
- importLoaders : 1 , // no postcss-loader
228
+ importLoaders : 2 , // with postcss-loader
215
229
sourceMap : false ,
216
230
modules : {
217
231
localIdentName : `[folder]-[name]-[local][emoji]`
@@ -236,10 +250,10 @@ test('css.extract', () => {
236
250
} , 'production' )
237
251
LANGS . forEach ( lang => {
238
252
const loader = lang === 'css' ? [ ] : LOADERS [ lang ]
239
- // when extract is false in production, even without postcss config,
240
- // an instance of postcss-loader is injected for inline minification.
241
- expect ( findLoaders ( config , lang ) ) . toEqual ( [ 'vue-style' , 'css' , 'postcss' ] . concat ( loader ) )
242
- expect ( findOptions ( config , lang , 'css' ) . importLoaders ) . toBe ( 2 )
253
+ // when extract is false in production,
254
+ // an additional instance of postcss-loader is injected for inline minification.
255
+ expect ( findLoaders ( config , lang ) ) . toEqual ( [ 'vue-style' , 'css' , 'postcss' , 'postcss' ] . concat ( loader ) )
256
+ expect ( findOptions ( config , lang , 'css' ) . importLoaders ) . toBe ( 3 )
243
257
expect ( findOptions ( config , lang , 'postcss' ) . plugins ) . toBeTruthy ( )
244
258
} )
245
259
@@ -380,10 +394,3 @@ test('should use dart sass implementation whenever possible', () => {
380
394
expect ( findOptions ( config , 'sass' , 'sass' ) ) . toMatchObject ( { implementation : require ( 'sass' ) } )
381
395
} )
382
396
383
- test ( 'skip postcss-loader if no postcss config found' , ( ) => {
384
- const config = genConfig ( )
385
- LANGS . forEach ( lang => {
386
- const loader = lang === 'css' ? [ ] : LOADERS [ lang ]
387
- expect ( findLoaders ( config , lang ) ) . toEqual ( [ 'vue-style' , 'css' ] . concat ( loader ) )
388
- } )
389
- } )
0 commit comments