@@ -238,12 +238,15 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
238
238
}
239
239
}
240
240
241
+ const postCss = require ( 'postcss' ) ;
242
+ const postCssLoaderPath = require . resolve ( 'postcss-loader' ) ;
243
+
241
244
const componentStyleLoaders : webpack . RuleSetUseItem [ ] = [
242
245
{ loader : require . resolve ( 'raw-loader' ) } ,
243
246
{
244
- loader : require . resolve ( 'postcss-loader' ) ,
247
+ loader : postCssLoaderPath ,
245
248
options : {
246
- implementation : require ( 'postcss' ) ,
249
+ implementation : postCss ,
247
250
postcssOptions : postcssOptionsCreator ( componentsSourceMap , false ) ,
248
251
} ,
249
252
} ,
@@ -263,28 +266,65 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
263
266
} ,
264
267
} ,
265
268
{
266
- loader : require . resolve ( 'postcss-loader' ) ,
269
+ loader : postCssLoaderPath ,
267
270
options : {
268
- implementation : require ( 'postcss' ) ,
271
+ implementation : postCss ,
269
272
postcssOptions : postcssOptionsCreator ( false , buildOptions . extractCss ) ,
270
273
sourceMap : ! ! cssSourceMap ,
271
274
} ,
272
275
} ,
273
276
] ;
274
277
278
+ const extraMinimizers = [ ] ;
279
+ if ( buildOptions . optimization . styles . minify ) {
280
+ const CssMinimizerPlugin = require ( 'css-minimizer-webpack-plugin' ) ;
281
+ const minimizerOptions = {
282
+ preset : [
283
+ 'default' ,
284
+ {
285
+ // Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
286
+ svgo : false ,
287
+ // Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
288
+ calc : false ,
289
+ // Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
290
+ cssDeclarationSorter : false ,
291
+ } ,
292
+ ] ,
293
+ } ;
294
+
295
+ const globalBundlesRegExp = new RegExp (
296
+ `^(${ Object . keys ( entryPoints ) . join ( '|' ) } )(\.[0-9a-f]{20})?.css$` ,
297
+ ) ;
298
+
299
+ extraMinimizers . push (
300
+ new CssMinimizerPlugin ( {
301
+ // Component styles retain their original file name
302
+ test : / \. (?: c s s | s c s s | s a s s | l e s s | s t y l ) $ / ,
303
+ parallel : false ,
304
+ exclude : globalBundlesRegExp ,
305
+ minify : [ CssMinimizerPlugin . cssnanoMinify ] ,
306
+ minimizerOptions,
307
+ } ) ,
308
+ new CssMinimizerPlugin ( {
309
+ test : / \. c s s $ / ,
310
+ include : globalBundlesRegExp ,
311
+ parallel : maxWorkers ,
312
+ minify : [ CssMinimizerPlugin . cssnanoMinify ] ,
313
+ minimizerOptions,
314
+ } ) ,
315
+ ) ;
316
+ }
317
+
275
318
const styleLanguages : {
276
319
extensions : string [ ] ;
277
- mimetype ?: string ;
278
320
use : webpack . RuleSetUseItem [ ] ;
279
321
} [ ] = [
280
322
{
281
323
extensions : [ 'css' ] ,
282
- mimetype : 'text/css' ,
283
324
use : [ ] ,
284
325
} ,
285
326
{
286
327
extensions : [ 'scss' ] ,
287
- mimetype : 'text/x-scss' ,
288
328
use : [
289
329
{
290
330
loader : require . resolve ( 'resolve-url-loader' ) ,
@@ -314,7 +354,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
314
354
} ,
315
355
{
316
356
extensions : [ 'sass' ] ,
317
- mimetype : 'text/x-sass' ,
318
357
use : [
319
358
{
320
359
loader : require . resolve ( 'resolve-url-loader' ) ,
@@ -328,6 +367,8 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
328
367
implementation : sassImplementation ,
329
368
sourceMap : true ,
330
369
sassOptions : {
370
+ // Prevent use of `fibers` package as it no longer works in newer Node.js versions
371
+ fiber : false ,
331
372
indentedSyntax : true ,
332
373
// bootstrap-sass requires a minimum precision of 8
333
374
precision : 8 ,
@@ -343,7 +384,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
343
384
} ,
344
385
{
345
386
extensions : [ 'less' ] ,
346
- mimetype : 'text/x-less' ,
347
387
use : [
348
388
{
349
389
loader : require . resolve ( 'less-loader' ) ,
@@ -360,7 +400,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
360
400
} ,
361
401
{
362
402
extensions : [ 'styl' ] ,
363
- mimetype : 'text/x-stylus' ,
364
403
use : [
365
404
{
366
405
loader : require . resolve ( 'stylus-loader' ) ,
@@ -377,84 +416,30 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
377
416
} ,
378
417
] ;
379
418
380
- const inlineLanguageRules : webpack . RuleSetRule [ ] = [ ] ;
381
- const fileLanguageRules : webpack . RuleSetRule [ ] = [ ] ;
382
- for ( const language of styleLanguages ) {
383
- if ( language . mimetype ) {
384
- // inline component styles use data URIs and processing is selected by mimetype
385
- inlineLanguageRules . push ( {
386
- mimetype : language . mimetype ,
387
- use : [ ...componentStyleLoaders , ...language . use ] ,
388
- } ) ;
389
- }
390
-
391
- fileLanguageRules . push ( {
392
- test : new RegExp ( `\\.(?:${ language . extensions . join ( '|' ) } )$` , 'i' ) ,
393
- rules : [
394
- // Setup processing rules for global and component styles
395
- {
396
- oneOf : [
397
- // Component styles are all styles except defined global styles
398
- {
399
- exclude : globalStylePaths ,
400
- use : componentStyleLoaders ,
401
- } ,
402
- // Global styles are only defined global styles
403
- {
404
- include : globalStylePaths ,
405
- use : globalStyleLoaders ,
406
- } ,
407
- ] ,
408
- } ,
409
- { use : language . use } ,
410
- ] ,
411
- } ) ;
412
- }
413
-
414
- const extraMinimizers = [ ] ;
415
- if ( buildOptions . optimization . styles . minify ) {
416
- const CssMinimizerPlugin = require ( 'css-minimizer-webpack-plugin' ) ;
417
- const minimizerOptions = {
418
- preset : [
419
- 'default' ,
420
- {
421
- // Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
422
- svgo : false ,
423
- // Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
424
- calc : false ,
425
- // Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
426
- cssDeclarationSorter : false ,
427
- } ,
428
- ] ,
429
- } ;
430
-
431
- const globalBundlesRegExp = new RegExp (
432
- `^(${ Object . keys ( entryPoints ) . join ( '|' ) } )(\.[0-9a-f]{20})?.css$` ,
433
- ) ;
434
-
435
- extraMinimizers . push (
436
- new CssMinimizerPlugin ( {
437
- // Component styles retain their original file name
438
- test : / \. (?: c s s | s c s s | s a s s | l e s s | s t y l ) $ / ,
439
- parallel : false ,
440
- exclude : globalBundlesRegExp ,
441
- minify : [ CssMinimizerPlugin . cssnanoMinify ] ,
442
- minimizerOptions,
443
- } ) ,
444
- new CssMinimizerPlugin ( {
445
- test : / \. c s s $ / ,
446
- include : globalBundlesRegExp ,
447
- parallel : maxWorkers ,
448
- minify : [ CssMinimizerPlugin . cssnanoMinify ] ,
449
- minimizerOptions,
450
- } ) ,
451
- ) ;
452
- }
453
-
454
419
return {
455
420
entry : entryPoints ,
456
421
module : {
457
- rules : [ ...fileLanguageRules , ...inlineLanguageRules ] ,
422
+ rules : styleLanguages . map ( ( { extensions, use } ) => ( {
423
+ test : new RegExp ( `\\.(?:${ extensions . join ( '|' ) } )$` , 'i' ) ,
424
+ rules : [
425
+ // Setup processing rules for global and component styles
426
+ {
427
+ oneOf : [
428
+ // Component styles are all styles except defined global styles
429
+ {
430
+ exclude : globalStylePaths ,
431
+ use : componentStyleLoaders ,
432
+ } ,
433
+ // Global styles are only defined global styles
434
+ {
435
+ include : globalStylePaths ,
436
+ use : globalStyleLoaders ,
437
+ } ,
438
+ ] ,
439
+ } ,
440
+ { use } ,
441
+ ] ,
442
+ } ) ) ,
458
443
} ,
459
444
optimization : {
460
445
minimizer : extraMinimizers ,
0 commit comments