-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvue.config.js
140 lines (132 loc) · 4.34 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const path = require('path')
const settings = require('./src/config/settings.js')
const SentryWebpackPlugin = require('@sentry/webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const { cliSettings, sentryCliSettings } = settings
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: cliSettings.publicPath,
outputDir: cliSettings.outputDir,
assetsDir: cliSettings.assetsDir,
productionSourceMap: true,
lintOnSave: process.env.NODE_ENV !== 'production',
devServer: {
port: cliSettings.devServerPort,
progress: false,
https: cliSettings.https,
disableHostCheck: true,
open: false,
overlay: {
warnings: false,
errors: true
},
proxy: {
'/': {
target: `http://120.79.204.212:9090`,
changeOrigin: true,
ws: true,
pathRewrite: {
['^' + '/']: ''
}
}
}
},
css: {
loaderOptions: {
sass: {
implementation: require('sass'),
sassOptions: {
fiber: require('fibers')
}
},
scss: {
prependData: `@import "~@/styles/index.scss";`
}
}
},
configureWebpack: {
resolve: {
alias: {
'@': resolve('src')
}
}
},
chainWebpack(config) {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
config.set('name', cliSettings.title)
// set preserveWhitespace
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
// https://webpack.js.org/configuration/devtool/#development
config
.when(process.env.NODE_ENV === 'development',
(config) => config.devtool('cheap-source-map')
)
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
commons: {
name: 'chunk-commons',
test: path.resolve(__dirname, 'src/components'),
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
})
config.optimization.runtimeChunk('single')
}
)
if (process.env.NODE_ENV === 'production') {
// sentry错误监控配置(自动上传sourcemap)
config.plugin('sentry').use(SentryWebpackPlugin, [{
ignore: ['node_modules'],
include: `${cliSettings.outputDir}/${cliSettings.assetsDir}/js`, // 上传的js
configFile: 'sentry.properties', // 配置文件地址
release: sentryCliSettings.release, // 版本号
urlPrefix: `~/${cliSettings.name}/${cliSettings.assetsDir}/js` // cdn js的代码路径前缀
}])
// 构建完成后自动删除sourceMap文件
config.plugin('clean').use(CleanWebpackPlugin, [
{
verbose: true, // 控制台打印信息
cleanOnceBeforeBuildPatterns: [], // 构建前不需要删除
cleanAfterEveryBuildPatterns: [`${cliSettings.assetsDir}/js/*.map`], // 构建完成后删除指定的文件
protectWebpackAssets: false // 必须设置为false否则文件不会被删除
}
])
}
// optionally replace with another progress output plugin
// `npm i -D simple-progress-webpack-plugin` to use
config.plugin('simple-progress-webpack-plugin').use(require.resolve('simple-progress-webpack-plugin'), [
{
format: 'minimal' // options are minimal, compact, expanded, verbose
}
])
}
}