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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
const path = require("path")
const {
publicPath,
assetsDir,
outputDir,
lintOnSave,
transpileDependencies,
title,
abbreviation,
devPort,
providePlugin,
build7z,
} = require("./src/config/settings")
const { version, author } = require("./package.json")
const Webpack = require("webpack")
const WebpackBar = require("webpackbar")
const FileManagerPlugin = require("filemanager-webpack-plugin")
const date = require("dayjs")().format("YYYY_M_D")
const time = require("dayjs")().format("YYYY-M-D HH:mm:ss")
const CompressionWebpackPlugin = require("compression-webpack-plugin")
const productionGzipExtensions = ["html", "js", "css", "svg"]
const IS_PROD = ["production", "prod"].includes(process.env.NODE_ENV)
process.env.VUE_APP_TITLE = title || "vue-admin-beautiful"
process.env.VUE_APP_AUTHOR = author || "chuzhixin"
process.env.VUE_APP_UPDATE_TIME = time
process.env.VUE_APP_VERSION = version
function resolve(dir) {
return path.join(__dirname, dir)
}
function mockServer() {
if (process.env.NODE_ENV === "development") {
const mockServer = require("./mock/mockServer.js")
return mockServer
} else {
return ""
}
}
const externals = {
// vue: "Vue",
// "vue-router": "VueRouter",
// vuex: "Vuex",
// axios: "axios",
// echarts: "echarts",
// lodash: "_",
// "element-ui": "ELEMENT",
}
// CDN外链,会插入到index.html中
const cdn = {
// 开发环境
dev: {
css: [],
js: [],
},
// 生产环境
build: {
css: [],
js: [
// "https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js",
// "https://cdn.jsdelivr.net/npm/vue-router@3.3.4/dist/vue-router.min.js",
// "https://cdn.jsdelivr.net/npm/axios@0.19.2/dist/axios.min.js",
// "https://cdn.jsdelivr.net/npm/vuex@3.4.0/dist/vuex.min.js",
// "https://cdn.jsdelivr.net/npm/echarts@5.1.2/dist/echarts.min.js",
// "https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js",
// "https://cdn.jsdelivr.net/npm/element-ui@2.15.3/lib/index.min.js",
],
},
}
module.exports = {
publicPath,
assetsDir,
outputDir,
lintOnSave,
transpileDependencies,
devServer: {
disableHostCheck: true,
hot: true,
port: devPort,
open: true,
noInfo: false,
overlay: {
warnings: false,
errors: true,
},
proxy: {
"/api": {
target: "http://192.168.31.140:11021/",
// target: "https://ds.cixincloud.com/geca-api/",
changeOrigin: true,
pathRewrite: {
"^/api": "",
},
},
},
// after: mockServer(),
},
configureWebpack(config) {
if (IS_PROD) {
config.externals = externals
}
return {
resolve: {
alias: {
"@": resolve("src"),
"^": resolve("src/components"),
packages: resolve("packages"),
},
},
plugins: [
new Webpack.ProvidePlugin(providePlugin),
new WebpackBar({
name: abbreviation,
}),
],
}
},
chainWebpack(config) {
config.plugins.delete("preload")
config.plugins.delete("prefetch")
config.resolve.symlinks(true)
config.plugin("html").tap((args) => {
if (IS_PROD) {
args[0].cdn = cdn.build
} else {
args[0].cdn = cdn.dev
}
return args
})
config.module
.rule("svg")
.exclude.add(resolve("src/remixIcon"))
.add(resolve("src/colorfulIcon"))
.end()
config.module
.rule("remixIcon")
.test(/\.svg$/)
.include.add(resolve("src/remixIcon"))
.end()
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({
symbolId: "remix-icon-[name]",
})
.end()
config.module
.rule("colorfulIcon")
.test(/\.svg$/)
.include.add(resolve("src/colorfulIcon"))
.end()
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({
symbolId: "colorful-icon-[name]",
})
.end()
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap((options) => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
config.when(process.env.NODE_ENV === "development", (config) => {
config.devtool("cheap-module-eval-source-map")
})
config.when(process.env.NODE_ENV !== "development", (config) => {
config.performance.set("hints", false)
config.devtool("none")
config
.plugin("ScriptExtHtmlWebpackPlugin")
.after("html")
.use("script-ext-html-webpack-plugin", [
{
inline: /runtime\..*\.js$/,
},
])
.end()
config.optimization.splitChunks({
chunks: "all",
cacheGroups: {
libs: {
name: "chunk-libs",
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: "initial",
},
elementUI: {
name: "chunk-elementUI",
priority: 20,
test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
},
fortawesome: {
name: "chunk-fortawesome",
priority: 20,
test: /[\\/]node_modules[\\/]_?@fortawesome(.*)/,
},
commons: {
name: "chunk-commons",
test: resolve("src/components"),
minChunks: 3,
priority: 5,
reuseExistingChunk: true,
},
},
})
config.optimization.runtimeChunk("single")
})
config
.plugin("compression")
.use(CompressionWebpackPlugin, [
{
filename: "[path].gz[query]",
algorithm: "gzip",
test: new RegExp("\\.(" + productionGzipExtensions.join("|") + ")$"),
threshold: 8192,
minRatio: 0.8,
},
])
.end()
if (build7z) {
config.when(process.env.NODE_ENV === "production", (config) => {
config
.plugin("fileManager")
.use(FileManagerPlugin, [
{
onEnd: {
delete: [`./${outputDir}/video`, `./${outputDir}/data`],
archive: [
{
source: `./${outputDir}`,
destination: `./${outputDir}/${abbreviation}.zip`,
},
],
},
},
])
.end()
})
}
},
runtimeCompiler: true,
productionSourceMap: false,
css: {
requireModuleExtension: true,
sourceMap: true,
loaderOptions: {
scss: {
prependData: '@import "~@/styles/variables.scss";',
},
},
},
}