@@ -64,6 +64,8 @@ module.exports = function (source) {
64
64
const BEFORE_TEMPLATE_COMPILER = utils . stringifyRequest ( this , beforeTemplateCompilerLoader ) . replace ( / " / g, '' )
65
65
66
66
67
+ const variableMap = this . vuxVariableMap || utils . getLoaderConfig ( this , 'vuxVariableMap' )
68
+
67
69
var query = this . query ? utils . parseQuery ( this . query ) : { }
68
70
this . cacheable ( )
69
71
if ( ! source ) return source
@@ -81,6 +83,14 @@ module.exports = function (source) {
81
83
const themePath = path . join ( config . options . projectRoot , themes [ 0 ] . path )
82
84
this . addDependency ( themePath )
83
85
variables = getLessVariables ( themes [ 0 ] . path )
86
+ for ( let i in variables ) {
87
+ if ( variableMap [ i ] ) {
88
+ variables [ variableMap [ i ] ] = variables [ i ]
89
+ if ( i !== variableMap [ i ] ) {
90
+ delete variables [ i ]
91
+ }
92
+ }
93
+ }
84
94
}
85
95
86
96
source = addScriptLoader ( source , SCRIPT )
@@ -333,6 +343,37 @@ module.exports.merge = function (oldConfig, vuxConfig) {
333
343
}
334
344
}
335
345
346
+ // get less variable alias
347
+ if ( hasPlugin ( 'vux-ui' , vuxConfig . plugins ) ) {
348
+ let variablePath = path . resolve ( vuxConfig . options . projectRoot , 'node_modules/vux/src/styles/variable.less' )
349
+ if ( vuxConfig . options . vuxDev ) {
350
+ variablePath = path . resolve ( vuxConfig . options . projectRoot , 'src/styles/variable.less' )
351
+ }
352
+ // parse alias
353
+
354
+ const rs = { }
355
+
356
+ try {
357
+ const content = fs . readFileSync ( variablePath , 'utf-8' ) . split ( '\n' ) . filter ( line => / \/ \/ \s a l i a s / . test ( line ) ) . map ( line => {
358
+ const value = line . split ( '// alias ' ) [ 1 ] . replace ( / \s + / g, '' ) . trim ( )
359
+ const key = line . split ( '// alias ' ) [ 0 ] . replace ( / \s + / g, '' ) . trim ( ) . split ( ':' ) [ 0 ] . replace ( / ^ @ / , '' )
360
+ return [ key , value ]
361
+ } ) . forEach ( one => {
362
+ rs [ one [ 0 ] ] = one [ 1 ]
363
+ } )
364
+ } catch ( e ) { }
365
+
366
+ if ( isWebpack2 ) {
367
+ config . plugins . push ( new webpack . LoaderOptionsPlugin ( {
368
+ vuxVariableMap : rs
369
+ } ) )
370
+ } else {
371
+ config = merge ( config , {
372
+ vuxVariableMap : rs
373
+ } )
374
+ }
375
+ }
376
+
336
377
/**
337
378
* ======== read vux locales and set globally ========
338
379
*/
0 commit comments