-
Notifications
You must be signed in to change notification settings - Fork 13
/
vue.config.js
95 lines (94 loc) · 2.48 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const isProd = process.env.NODE_ENV === 'production'
const path = require('path')
const fs = require('fs')
// const HtmlWebpackPlugin = require('html-webpack-plugin')
function resolve(filePath) {
return path.join(__dirname, filePath)
}
const getEntries = dir => {
let absolutionPath = path.resolve(dir)
let sonFiles = fs.readdirSync(absolutionPath)
let entries = {}
sonFiles.forEach(file => {
let fileDirPath = path.join(absolutionPath, file)
if (fs.statSync(fileDirPath).isDirectory()) {
let filePath = path.join(fileDirPath, 'index.js')
entries[file] = filePath
}
})
return entries
}
const commonConfig = {
publicPath: '/',
devServer: {
host: 'dev.axe-ui.com',
port: 8080,
disableHostCheck: true
},
chainWebpack: config => {
config.resolve.alias
.set('packages', resolve('packages'))
.set('comp', resolve('src/components'))
.set('axe-ui', resolve('./'))
.set('style', resolve('styles'))
},
configureWebpack: {
// plugins: [
// new HtmlWebpackPlugin({
// title: '组件库',
// template: 'public/index.html'
// })
// ]
}
}
let buildConfig = {}
// 按需加载(build命令&&后第二个脚本,为按需加载打包)
const args = process.argv.slice(2)
if (isProd && args.includes('--axe')) {
buildConfig = {
outputDir: 'dist',
configureWebpack: {
entry: {
...getEntries('./packages')
},
output: {
filename: 'lib/[name]/index.js',
libraryTarget: 'umd',
libraryExport: 'default',
library: ['axe', '[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')
// [temp] Building for production, need to optimize
config.resolve.alias
.set('packages', resolve('packages'))
.set('comp', resolve('src/components'))
.set('axe-ui', resolve('./'))
.set('style', resolve('styles'))
}
}
}
module.exports = !isProd
? commonConfig
: Object.assign(commonConfig, buildConfig)