Skip to content

Commit f52e96d

Browse files
committed
support alias to original weui variables
1 parent a8cc0dd commit f52e96d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vux-loader",
3-
"version": "1.2.7",
3+
"version": "1.2.8",
44
"description": "extended loader for vue-loader",
55
"main": "src/index.js",
66
"keywords": [

src/index.js

+41
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ module.exports = function (source) {
6464
const BEFORE_TEMPLATE_COMPILER = utils.stringifyRequest(this, beforeTemplateCompilerLoader).replace(/"/g, '')
6565

6666

67+
const variableMap = this.vuxVariableMap || utils.getLoaderConfig(this, 'vuxVariableMap')
68+
6769
var query = this.query ? utils.parseQuery(this.query) : {}
6870
this.cacheable()
6971
if (!source) return source
@@ -81,6 +83,14 @@ module.exports = function (source) {
8183
const themePath = path.join(config.options.projectRoot, themes[0].path)
8284
this.addDependency(themePath)
8385
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+
}
8494
}
8595

8696
source = addScriptLoader(source, SCRIPT)
@@ -333,6 +343,37 @@ module.exports.merge = function (oldConfig, vuxConfig) {
333343
}
334344
}
335345

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 => /\/\/\salias/.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+
336377
/**
337378
* ======== read vux locales and set globally ========
338379
*/

0 commit comments

Comments
 (0)