xiaoju-survey/web/vue.config.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

2023-11-02 12:12:37 +00:00
const { defineConfig } = require('@vue/cli-service');
2023-12-01 08:13:51 +00:00
const Webpack = require('webpack')
// 分析打包时间
const SpeedMeasureWebpackPlugin = require('speed-measure-webpack-plugin')
2023-11-02 12:12:37 +00:00
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave: false,
pages: {
management: {
entry: `src/management/main.js`,
template: 'public/management.html',
filename: `management.html`,
title: '问卷调研',
},
render: {
entry: `src/render/main.js`,
template: 'public/render.html',
filename: `render.html`,
title: '问卷调研',
},
},
css: {
loaderOptions: {
sass: {
additionalData: `@import "./src/management/styles/variable.scss";`,
},
},
},
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000',
2023-11-02 12:12:37 +00:00
changeOrigin: true,
},
},
setupMiddlewares(middlewares, devServer) {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
devServer.app.get('/', function (req, res) {
res.redirect('/management');
});
return middlewares;
},
open: true,
2023-11-02 12:12:37 +00:00
},
2023-12-01 08:13:51 +00:00
configureWebpack: {
plugins: [new Webpack.IgnorePlugin({resourceRegExp: /^\.\/locale$/, contextRegExp: /moment$/ })],
},
2023-11-02 12:12:37 +00:00
chainWebpack: (config) => {
config.module
.rule('js')
.test(/\.jsx?$/)
2023-12-01 08:13:51 +00:00
.exclude
.add(/node_modules/)
.end()
2023-11-02 12:12:37 +00:00
.use('babel-loader')
.loader('babel-loader')
.end();
2023-12-01 08:13:51 +00:00
2023-11-02 12:12:37 +00:00
config.optimization.splitChunks({
cacheGroups: {
setterWidgets: {
2023-12-01 08:13:51 +00:00
name: 'chunk-setterWidgets',
test: /\/materials\/setters[\\/]/,
2023-11-02 12:12:37 +00:00
chunks: 'async',
enforce: true,
},
materialWidgets: {
2023-12-01 08:13:51 +00:00
name: 'chunk-materialWidgets',
test: /\/materials\/questions[\\/]/,
2023-11-02 12:12:37 +00:00
chunks: 'async',
enforce: true,
},
2023-12-01 08:13:51 +00:00
commonEditor: {
name: 'chunk-commonEditor',
test: /\/common\/Editor[\\/]/,
enforce: true,
},
element: {
name: 'chunk-element-ui',
test: /[\\/]node_modules[\\/]element-ui[\\/]/,
chunks: "all",
priority: 3,
reuseExistingChunk: true,
enforce: true
},
moment: {
name: 'chunk-moment',
test: /[\\/]node_modules[\\/]moment[\\/]/,
chunks: "all",
priority: 3,
reuseExistingChunk: true,
enforce: true
},
'@wangeditor': {
name: 'chunk-wangeditor',
test: /[\\/]node_modules[\\/]@wangeditor[\\/]/,
chunks: "all",
priority: 3,
reuseExistingChunk: true,
enforce: true
},
common: {
//抽取所有入口页面都需要的公共chunk
name: "chunk-common",
chunks: "initial",
minChunks: 2,
maxInitialRequests: 5,
minSize: 0,
priority: 1,
reuseExistingChunk: true,
enforce: true
}
2023-11-02 12:12:37 +00:00
},
});
2023-12-01 08:13:51 +00:00
config.plugin('speed')
.use(SpeedMeasureWebpackPlugin)
2023-11-02 12:12:37 +00:00
},
});