-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpackCompileParams.js
76 lines (67 loc) · 2.32 KB
/
webpackCompileParams.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const path = require("path")
const fs = require('fs')
const projectRootPath = path.resolve(__dirname, './')
let isUse = true
let start_params
try {
start_params = JSON.parse(process.env.npm_config_argv)
if (!start_params || start_params && (!start_params.original || start_params.original.length == 1)) {
start_params = false
}
start_params = start_params.original.join('').toUpperCase()
//console.log('start_params:' + start_params)
} catch (err) {
start_params = false
}
const moduleConfig = {
useEDF: {
path: './apps/edf/',
name: 'edf',
less: 'edf'
},
originalStyle:{
path: './apps/originalStyle/',
name: 'originalStyle',
less: 'originalStyle'
}
}
function checkRunParams(name) {
if (!start_params) return true
if (start_params.indexOf('--ARG') == -1) return true
console.log(`***********检测${name}模块是否编译***********`, start_params.split('=')[1].split(' ').includes(name.toUpperCase()))
return start_params.split('=')[1].split(' ').includes(name.toUpperCase())
}
function checkModule() {
let target = {}
for (const key in moduleConfig) {
const value = moduleConfig[key]
target[key] = fs.existsSync(path.resolve(projectRootPath, `${value.path}/index.less`)) ? checkRunParams(value.name) : false
}
return target
}
function webpackCompileParams(mode) {
const checkParams = checkModule()
const modifyVars = {}
for (const key in moduleConfig) {
const value = moduleConfig[key]
modifyVars[`@${value.less}`] = checkParams[key] && isUse ? value.less : 'empty'
}
const aliasModule = {}
for (const key in moduleConfig) {
const value = moduleConfig[key]
if (mode == 'development') {
aliasModule[key] = checkParams[key] && isUse ? path.resolve(projectRootPath, `${value.path}/index.js`) : './empty.js'
} else {
aliasModule[key] = path.resolve(projectRootPath, `./modules/${value.name}.js`)
}
}
// for( const [key, value] of Object.entries(moduleConfig) ) {
// aliasModule[key] = checkParams[key] && isUse ? path.resolve(projectRootPath, `${value.path}/index.js`) : './empty.js'
// }
return {
modifyVars,
aliasModule,
start_params
}
}
module.exports = webpackCompileParams