File tree 5 files changed +70
-9
lines changed
5 files changed +70
-9
lines changed Original file line number Diff line number Diff line change @@ -581,6 +581,25 @@ class Encore {
581
581
return this ;
582
582
}
583
583
584
+ /**
585
+ * Configure the css-loader.
586
+ *
587
+ * https://github.com/webpack-contrib/css-loader#options
588
+ *
589
+ * Encore.configureCssLoader(function(config) {
590
+ * // change the config
591
+ * // config.minimize = true;
592
+ * });
593
+ *
594
+ * @param {function } callback
595
+ * @returns {Encore }
596
+ */
597
+ configureCssLoader ( callback ) {
598
+ webpackConfig . configureCssLoader ( callback ) ;
599
+
600
+ return this ;
601
+ }
602
+
584
603
/**
585
604
* If enabled, the react preset is added to Babel.
586
605
*
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ class WebpackConfig {
86
86
this . lessLoaderOptionsCallback = ( ) => { } ;
87
87
this . stylusLoaderOptionsCallback = ( ) => { } ;
88
88
this . babelConfigurationCallback = ( ) => { } ;
89
+ this . cssLoaderConfigurationCallback = ( ) => { } ;
89
90
this . vueLoaderOptionsCallback = ( ) => { } ;
90
91
this . eslintLoaderOptionsCallback = ( ) => { } ;
91
92
this . tsConfigurationCallback = ( ) => { } ;
@@ -319,6 +320,14 @@ class WebpackConfig {
319
320
this . babelConfigurationCallback = callback ;
320
321
}
321
322
323
+ configureCssLoader ( callback ) {
324
+ if ( typeof callback !== 'function' ) {
325
+ throw new Error ( 'Argument 1 to configureCssLoader() must be a callback function.' ) ;
326
+ }
327
+
328
+ this . cssLoaderConfigurationCallback = callback ;
329
+ }
330
+
322
331
createSharedEntry ( name , files ) {
323
332
// don't allow to call this twice
324
333
if ( this . sharedCommonsEntryName ) {
Original file line number Diff line number Diff line change @@ -21,18 +21,20 @@ module.exports = {
21
21
getLoaders ( webpackConfig , skipPostCssLoader ) {
22
22
const usePostCssLoader = webpackConfig . usePostCssLoader && ! skipPostCssLoader ;
23
23
24
+ const options = {
25
+ minimize : webpackConfig . isProduction ( ) ,
26
+ sourceMap : webpackConfig . useSourceMaps ,
27
+ // when using @import , how many loaders *before* css-loader should
28
+ // be applied to those imports? This defaults to 0. When postcss-loader
29
+ // is used, we set it to 1, so that postcss-loader is applied
30
+ // to @import resources.
31
+ importLoaders : usePostCssLoader ? 1 : 0
32
+ } ;
33
+
24
34
const cssLoaders = [
25
35
{
26
36
loader : 'css-loader' ,
27
- options : {
28
- minimize : webpackConfig . isProduction ( ) ,
29
- sourceMap : webpackConfig . useSourceMaps ,
30
- // when using @import , how many loaders *before* css-loader should
31
- // be applied to those imports? This defaults to 0. When postcss-loader
32
- // is used, we set it to 1, so that postcss-loader is applied
33
- // to @import resources.
34
- importLoaders : usePostCssLoader ? 1 : 0
35
- }
37
+ options : applyOptionsCallback ( webpackConfig . cssLoaderConfigurationCallback , options )
36
38
} ,
37
39
] ;
38
40
Original file line number Diff line number Diff line change @@ -436,6 +436,23 @@ describe('WebpackConfig object', () => {
436
436
} ) ;
437
437
} ) ;
438
438
439
+ describe ( 'configureCssLoader' , ( ) => {
440
+ it ( 'Calling method sets it' , ( ) => {
441
+ const config = createConfig ( ) ;
442
+ const testCallback = ( ) => { } ;
443
+ config . configureCssLoader ( testCallback ) ;
444
+ expect ( config . cssLoaderConfigurationCallback ) . to . equal ( testCallback ) ;
445
+ } ) ;
446
+
447
+ it ( 'Calling with non-callback throws an error' , ( ) => {
448
+ const config = createConfig ( ) ;
449
+
450
+ expect ( ( ) => {
451
+ config . configureCssLoader ( 'FOO' ) ;
452
+ } ) . to . throw ( 'must be a callback function' ) ;
453
+ } ) ;
454
+ } ) ;
455
+
439
456
describe ( 'enablePostCssLoader' , ( ) => {
440
457
it ( 'Call with no config' , ( ) => {
441
458
const config = createConfig ( ) ;
Original file line number Diff line number Diff line change @@ -44,6 +44,20 @@ describe('loaders/css', () => {
44
44
expect ( actualLoaders [ 0 ] . options . minimize ) . to . be . true ;
45
45
} ) ;
46
46
47
+ it ( 'getLoaders() with options callback' , ( ) => {
48
+ const config = createConfig ( ) ;
49
+
50
+ config . configureCssLoader ( function ( options ) {
51
+ options . minimize = true ;
52
+ options . url = false ;
53
+ } ) ;
54
+
55
+ const actualLoaders = cssLoader . getLoaders ( config ) ;
56
+ expect ( actualLoaders ) . to . have . lengthOf ( 1 ) ;
57
+ expect ( actualLoaders [ 0 ] . options . minimize ) . to . be . true ;
58
+ expect ( actualLoaders [ 0 ] . options . url ) . to . be . false ;
59
+ } ) ;
60
+
47
61
describe ( 'getLoaders() with PostCSS' , ( ) => {
48
62
it ( 'without options callback' , ( ) => {
49
63
const config = createConfig ( ) ;
You can’t perform that action at this time.
0 commit comments