File tree Expand file tree Collapse file tree 6 files changed +38
-15
lines changed Expand file tree Collapse file tree 6 files changed +38
-15
lines changed Original file line number Diff line number Diff line change @@ -347,11 +347,19 @@ module.exports = {
347
347
*
348
348
* https://github.com/vuejs/vue-loader
349
349
*
350
- * @param {object } vueLoaderOptions: https://vue-loader.vuejs.org/en/configurations/advanced.html
350
+ * Encore.enableVueLoader();
351
+ *
352
+ * // or configure the vue-loader options
353
+ * // https://vue-loader.vuejs.org/en/configurations/advanced.html
354
+ * Encore.enableVueLoader(function(options) {
355
+ * options.preLoaders = { ... }
356
+ * });
357
+ *
358
+ * @param {function } vueLoaderOptionsCallback
351
359
* @returns {exports }
352
360
*/
353
- enableVueLoader ( vueLoaderOptions = { } ) {
354
- webpackConfig . enableVueLoader ( vueLoaderOptions ) ;
361
+ enableVueLoader ( vueLoaderOptionsCallback = ( ) => { } ) {
362
+ webpackConfig . enableVueLoader ( vueLoaderOptionsCallback ) ;
355
363
356
364
return this ;
357
365
} ,
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ class WebpackConfig {
51
51
this . babelConfigurationCallback = function ( ) { } ;
52
52
this . useReact = false ;
53
53
this . useVueLoader = false ;
54
- this . vueLoaderOptions = { } ;
54
+ this . vueLoaderOptionsCallback = ( ) => { } ;
55
55
this . loaders = [ ] ;
56
56
}
57
57
@@ -224,9 +224,14 @@ class WebpackConfig {
224
224
this . useReact = true ;
225
225
}
226
226
227
- enableVueLoader ( vueLoaderOptions = { } ) {
227
+ enableVueLoader ( vueLoaderOptionsCallback = ( ) => { } ) {
228
228
this . useVueLoader = true ;
229
- this . vueLoaderOptions = vueLoaderOptions ;
229
+
230
+ if ( typeof vueLoaderOptionsCallback !== 'function' ) {
231
+ throw new Error ( 'Argument 1 to enableVueLoader() must be a callback function.' ) ;
232
+ }
233
+
234
+ this . vueLoaderOptionsCallback = vueLoaderOptionsCallback ;
230
235
}
231
236
232
237
cleanupOutputBeforeBuild ( ) {
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ class ConfigGenerator {
155
155
if ( this . webpackConfig . useVueLoader ) {
156
156
rules . push ( {
157
157
test : / \. v u e $ / ,
158
- use : vueLoaderUtil . getLoaders ( this . webpackConfig , this . webpackConfig . vueLoaderOptions )
158
+ use : vueLoaderUtil . getLoaders ( this . webpackConfig , this . webpackConfig . vueLoaderOptionsCallback )
159
159
} ) ;
160
160
}
161
161
Original file line number Diff line number Diff line change @@ -18,10 +18,11 @@ const extractText = require('./extract-text');
18
18
19
19
/**
20
20
* @param {WebpackConfig } webpackConfig
21
+ * @param {function } vueLoaderOptionsCallback
21
22
* @return {Array } of loaders to use for Vue files
22
23
*/
23
24
module . exports = {
24
- getLoaders ( webpackConfig , vueLoaderOptions ) {
25
+ getLoaders ( webpackConfig , vueLoaderOptionsCallback ) {
25
26
loaderFeatures . ensureLoaderPackagesExist ( 'vue' ) ;
26
27
27
28
/*
@@ -116,12 +117,16 @@ module.exports = {
116
117
} ;
117
118
}
118
119
120
+ let options = {
121
+ loaders : loaders
122
+ } ;
123
+ // allow the options to be mutated via a callback
124
+ vueLoaderOptionsCallback ( options ) ;
125
+
119
126
return [
120
127
{
121
128
loader : 'vue-loader' ,
122
- options : Object . assign ( {
123
- loaders : loaders
124
- } , vueLoaderOptions )
129
+ options : options
125
130
}
126
131
] ;
127
132
}
Original file line number Diff line number Diff line change @@ -301,10 +301,13 @@ describe('WebpackConfig object', () => {
301
301
302
302
it ( 'Pass config' , ( ) => {
303
303
const config = createConfig ( ) ;
304
- config . enableVueLoader ( { preLoaders : { foo : 'foo-loader' } } ) ;
304
+ const callback = ( options ) => {
305
+ options . preLoaders = { foo : 'foo-loader' } ;
306
+ } ;
307
+ config . enableVueLoader ( callback ) ;
305
308
306
309
expect ( config . useVueLoader ) . to . be . true ;
307
- expect ( config . vueLoaderOptions . preLoaders . foo ) . to . equal ( 'foo-loader' ) ;
310
+ expect ( config . vueLoaderOptionsCallback ) . to . equal ( callback ) ;
308
311
} ) ;
309
312
} ) ;
310
313
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ describe('loaders/vue', () => {
31
31
// enable postcss, then really prove that its loader does not show up below
32
32
config . enablePostCssLoader ( ) ;
33
33
34
- const actualLoaders = vueLoader . getLoaders ( config , { } ) ;
34
+ const actualLoaders = vueLoader . getLoaders ( config , ( ) => { } ) ;
35
35
expect ( actualLoaders ) . to . have . lengthOf ( 1 ) ;
36
36
expect ( Object . keys ( actualLoaders [ 0 ] . options . loaders ) ) . to . have . lengthOf ( 5 ) ;
37
37
@@ -46,7 +46,9 @@ describe('loaders/vue', () => {
46
46
47
47
const actualLoaders = vueLoader . getLoaders (
48
48
config ,
49
- { postLoaders : { foo : 'foo-loader' } }
49
+ ( options ) => {
50
+ options . postLoaders = { foo : 'foo-loader' } ;
51
+ }
50
52
) ;
51
53
52
54
expect ( actualLoaders ) . to . have . lengthOf ( 1 ) ;
You can’t perform that action at this time.
0 commit comments