-
Notifications
You must be signed in to change notification settings - Fork 2
/
generator.js
55 lines (48 loc) · 1.47 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
47
48
49
50
51
52
53
54
55
module.exports = (api, options) => {
// Adds vue as externals
if (options.addExternals) {
api.postProcessFiles(files => {
const vueConfigPath = api.resolve('vue.config.js');
const vueConfig = files['vue.config.js'] ? require(vueConfigPath) : {};
vueConfig.configureWebpack = vueConfig.configureWebpack || {};
vueConfig.configureWebpack.externals = {
...(vueConfig.configureWebpack.externals || {}),
...{
vue: 'vue',
'vue-property-decorator': 'vue-property-decorator'
}
};
files['vue.config.js'] = api.genJSConfig(vueConfig)
});
}
// Build command
let buildCommand = 'vue-cli-service build';
if (options.buildAsLib || options.mode === 'awesome') {
buildCommand += ' --target lib ';
buildCommand += options.main ? options.main : 'src/main.ts';
}
if (options.bundleAfterBuild || options.mode === 'awesome') {
buildCommand += ' && npm run bundleDts';
}
// Bundle command
let bundleDtsCommand = 'vue-cli-service bundle-dts';
if (options.name) {
bundleDtsCommand += ` --name ${options.name}`;
}
if (options.baseDir) {
bundleDtsCommand += ` --baseDir ${options.baseDir}`;
}
if (options.main) {
bundleDtsCommand += ` --main ${options.main}`;
}
if (options.removeSource) {
bundleDtsCommand += ' --removeSource';
}
// Extend package.json
api.extendPackage({
scripts: {
'build': buildCommand,
'bundleDts': bundleDtsCommand,
}
});
}