File tree Expand file tree Collapse file tree 6 files changed +90
-11
lines changed Expand file tree Collapse file tree 6 files changed +90
-11
lines changed Original file line number Diff line number Diff line change 1
1
# CHANGELOG
2
2
3
+ ## 0.10.0
4
+
5
+ * [ BC BREAK] If you're using ` enableSassLoader() ` AND passing an options
6
+ array, the options now need to be moved to the second argument:
7
+
8
+ ``` js
9
+ // before
10
+ .enableSassLoader ({ resolve_url_loader: true });
11
+
12
+ // after
13
+ enableSassLoader (function (sassOptions ) {}, {
14
+ resolve_url_loader: true
15
+ })
16
+ ```
17
+
3
18
## 0.9.1
4
19
5
20
* Syntax error fix - #64
Original file line number Diff line number Diff line change @@ -282,6 +282,18 @@ module.exports = {
282
282
/**
283
283
* Call this if you plan on loading SASS files.
284
284
*
285
+ * Encore.enableSassLoader();
286
+ *
287
+ * Or pass options to node-sass
288
+ *
289
+ * Encore.enableSassLoader(function(options) {
290
+ * // https://github.com/sass/node-sass#options
291
+ * // options.includePaths = [...]
292
+ * }, {
293
+ * // set optional Encore-specific options
294
+ * // resolve_url_loader: true
295
+ * });
296
+ *
285
297
* Supported options:
286
298
* * {bool} resolve_url_loader (default=true)
287
299
* Whether or not to use the resolve-url-loader.
@@ -291,11 +303,12 @@ module.exports = {
291
303
* to the original entry file... not whatever file
292
304
* the url() appears in.
293
305
*
294
- * @param {object } options
306
+ * @param {function } sassLoaderOptionsCallback
307
+ * @param {object } encoreOptions
295
308
* @return {exports }
296
309
*/
297
- enableSassLoader ( options = { } ) {
298
- webpackConfig . enableSassLoader ( options ) ;
310
+ enableSassLoader ( sassLoaderOptionsCallback = ( ) => { } , encoreOptions = { } ) {
311
+ webpackConfig . enableSassLoader ( sassLoaderOptionsCallback , encoreOptions ) ;
299
312
300
313
return this ;
301
314
} ,
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class WebpackConfig {
41
41
this . useSourceMaps = false ;
42
42
this . usePostCssLoader = false ;
43
43
this . useSassLoader = false ;
44
+ this . sassLoaderOptionsCallback = function ( ) { } ;
44
45
this . sassOptions = {
45
46
resolve_url_loader : true
46
47
} ;
@@ -206,9 +207,15 @@ class WebpackConfig {
206
207
this . usePostCssLoader = true ;
207
208
}
208
209
209
- enableSassLoader ( options = { } ) {
210
+ enableSassLoader ( sassLoaderOptionsCallback = ( ) => { } , options = { } ) {
210
211
this . useSassLoader = true ;
211
212
213
+ if ( typeof sassLoaderOptionsCallback !== 'function' ) {
214
+ throw new Error ( 'Argument 1 to enableSassLoader() must be a callback function.' ) ;
215
+ }
216
+
217
+ this . sassLoaderOptionsCallback = sassLoaderOptionsCallback ;
218
+
212
219
for ( const optionKey of Object . keys ( options ) ) {
213
220
if ( ! ( optionKey in this . sassOptions ) ) {
214
221
throw new Error ( `Invalid option "${ optionKey } " passed to enableSassLoader(). Valid keys are ${ Object . keys ( this . sassOptions ) . join ( ', ' ) } ` ) ;
Original file line number Diff line number Diff line change @@ -35,12 +35,21 @@ module.exports = {
35
35
} ) ;
36
36
}
37
37
38
+ let config = Object . assign ( { } , sassOptions , {
39
+ // needed by the resolve-url-loader
40
+ sourceMap : ( true === webpackConfig . sassOptions . resolve_url_loader ) || webpackConfig . useSourceMaps
41
+ } ) ;
42
+
43
+ // allow options to be configured
44
+ webpackConfig . sassLoaderOptionsCallback . apply (
45
+ // use config as the this variable
46
+ config ,
47
+ [ config ]
48
+ ) ;
49
+
38
50
sassLoaders . push ( {
39
51
loader : 'sass-loader' ,
40
- options : Object . assign ( { } , sassOptions , {
41
- // needed by the resolve-url-loader
42
- sourceMap : ( true === webpackConfig . sassOptions . resolve_url_loader ) || webpackConfig . useSourceMaps
43
- } ) ,
52
+ options : config ,
44
53
} ) ;
45
54
46
55
return sassLoaders ;
Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ describe('WebpackConfig object', () => {
263
263
264
264
it ( 'Pass valid config' , ( ) => {
265
265
const config = createConfig ( ) ;
266
- config . enableSassLoader ( { resolve_url_loader : false } ) ;
266
+ config . enableSassLoader ( ( ) => { } , { resolve_url_loader : false } ) ;
267
267
268
268
expect ( config . useSassLoader ) . to . be . true ;
269
269
expect ( config . sassOptions . resolve_url_loader ) . to . be . false ;
@@ -273,9 +273,17 @@ describe('WebpackConfig object', () => {
273
273
const config = createConfig ( ) ;
274
274
275
275
expect ( ( ) => {
276
- config . enableSassLoader ( { fake_option : false } ) ;
276
+ config . enableSassLoader ( ( ) => { } , { fake_option : false } ) ;
277
277
} ) . to . throw ( 'Invalid option "fake_option" passed to enableSassLoader()' ) ;
278
278
} ) ;
279
+
280
+ it ( 'Pass options callback' , ( ) => {
281
+ const config = createConfig ( ) ;
282
+ const callback = ( sassOptions ) => { } ;
283
+ config . enableSassLoader ( callback ) ;
284
+
285
+ expect ( config . sassLoaderOptionsCallback ) . to . equal ( callback ) ;
286
+ } ) ;
279
287
} ) ;
280
288
281
289
describe ( 'enableTypeScriptLoader' , ( ) => {
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ describe('loaders/sass', () => {
66
66
67
67
it ( 'getLoaders() without resolve-url-loader' , ( ) => {
68
68
const config = createConfig ( ) ;
69
- config . enableSassLoader ( {
69
+ config . enableSassLoader ( ( ) => { } , {
70
70
resolve_url_loader : false ,
71
71
} ) ;
72
72
config . enableSourceMaps ( false ) ;
@@ -100,4 +100,31 @@ describe('loaders/sass', () => {
100
100
101
101
cssLoader . getLoaders . restore ( ) ;
102
102
} ) ;
103
+
104
+ it ( 'getLoaders() with options callback' , ( ) => {
105
+ const config = createConfig ( ) ;
106
+
107
+ // make the cssLoader return nothing
108
+ sinon . stub ( cssLoader , 'getLoaders' )
109
+ . callsFake ( ( ) => [ ] ) ;
110
+
111
+ config . enableSassLoader ( function ( sassOptions ) {
112
+ sassOptions . custom_optiona = 'baz' ;
113
+ sassOptions . other_option = true ;
114
+ } ) ;
115
+
116
+ const actualLoaders = sassLoader . getLoaders ( config , {
117
+ custom_optiona : 'foo' ,
118
+ custom_optionb : 'bar'
119
+ } ) ;
120
+
121
+ expect ( actualLoaders [ 1 ] . options ) . to . deep . equals ( {
122
+ sourceMap : true ,
123
+ // callback wins over passed in options
124
+ custom_optiona : 'baz' ,
125
+ custom_optionb : 'bar' ,
126
+ other_option : true
127
+ } ) ;
128
+ cssLoader . getLoaders . restore ( ) ;
129
+ } ) ;
103
130
} ) ;
You can’t perform that action at this time.
0 commit comments