-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
63 lines (59 loc) · 1.49 KB
/
vue.config.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
const fs = require('fs')
const { resolve, join } = require('path')
const ARGS = process.argv.slice(2)
const NODE_ENV = process.env.NODE_ENV
const getEntries = (path) => {
const entries = {}
const absPath = resolve(path)
const dirs = fs.readdirSync(absPath)
console.log(absPath)
console.log(dirs)
dirs.forEach(dir => {
let p = join(absPath, dir)
if (fs.statSync(p).isDirectory()) {
p = join(p, 'index.js')
entries[dir] = p
}
})
return entries
}
// 按需打包,用户可以按需引入
if (ARGS.includes('--all') && NODE_ENV === 'production') {
module.exports = {
outputDir: 'dist',
configureWebpack: {
entry: {
...getEntries('./src/packages')
},
output: {
filename: 'lib/[name]/index.js',
libraryTarget: 'umd', // 打包结果
libraryExport: 'default',
library: ['yui', '[name]'] // 打包文件名
},
externals: {
vue: {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue'
}
}
},
css: {
sourceMap: true,
extract: {
filename: 'css/[name]/style.css'
}
},
chainWebpack: config => { // 删除默认配置
config.optimization.delete('splitChunks')
config.plugins.delete('copy')
config.plugins.delete('preload')
config.plugins.delete('prefetch')
config.plugins.delete('html')
config.plugins.delete('hmr')
config.entryPoints.delete('app')
}
}
}