-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgenerator.js
46 lines (39 loc) · 1.26 KB
/
generator.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
const chainWebpack = config => {
config.module
.rule('svg-sprite')
.use('svgo-loader')
.loader('svgo-loader')
};
module.exports = (api, options, rootOptions) => {
api.render('./template');
if (options.addSvgoLoader) {
const fs = require('fs');
api.extendPackage({
devDependencies: {
'svgo': '^1.1.0',
'svgo-loader': '^2.1.0',
},
});
let hasChainWebpackOption = false;
const vueConfig = api.resolve('vue.config.js');
if (fs.existsSync(vueConfig)) {
let projectOptions = require(vueConfig);
if (projectOptions.chainWebpack) {
hasChainWebpackOption = true;
}
}
if (hasChainWebpackOption) {
const {chalk} = require('@vue/cli-shared-utils');
const message = `Please add the following config to your ${chalk.cyan('chainWebpack')} method:` +
'\n\n' +
chalk.green(`config.module.rule('svg-sprite').use('svgo-loader').loader('svgo-loader');`);
api.exitLog(message, 'info');
} else {
api.extendPackage({
vue: {
chainWebpack,
},
});
}
}
};