travel/admin/vue.config.js

143 lines
5.0 KiB
JavaScript
Raw Normal View History

2024-10-21 11:20:32 +08:00
"use strict";
const path = require("path");
const defaultSettings = require("./src/settings.js");
2024-06-24 11:52:30 +08:00
function resolve(dir) {
2024-10-21 11:20:32 +08:00
return path.join(__dirname, dir);
2024-06-24 11:52:30 +08:00
}
2024-10-21 11:20:32 +08:00
const name = defaultSettings.title || "vue Element Admin"; // page title
2024-06-24 11:52:30 +08:00
// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
// You can change the port by the following method:
// port = 9527 npm run dev OR npm run dev --port = 9527
2024-10-21 11:20:32 +08:00
const port = process.env.port || process.env.npm_config_port || 9527; // dev port
2024-06-24 11:52:30 +08:00
// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
/**
* You will need to set publicPath if you plan to deploy your site under a sub path,
* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
* then publicPath should be set to "/bar/".
* In most cases please use '/' !!!
* Detail: https://cli.vuejs.org/config/#publicpath
*/
2024-10-21 11:20:32 +08:00
publicPath: "/",
outputDir: "../service/public",
assetsDir: "static",
lintOnSave: process.env.NODE_ENV === "development",
2024-06-24 11:52:30 +08:00
productionSourceMap: false,
devServer: {
port: port,
open: true,
overlay: {
warnings: false,
2024-10-21 11:20:32 +08:00
errors: true,
2024-06-24 11:52:30 +08:00
},
proxy: {
2024-10-21 11:20:32 +08:00
"/dev-api": {
// 接口地址 以 api开头的都走下面的配置
2024-11-25 10:16:31 +08:00
target: 'https://www.szjinao.cn', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2
// target: "http://hex.jipinq.cn", // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2
2024-11-25 10:11:30 +08:00
// target: "http://192.168.0.100:8787",
2024-06-24 11:52:30 +08:00
ws: true, // 是否支持 websocket 请求 支持
changeOrigin: true, // 是否启用跨域
pathRewrite: {
2024-10-21 11:20:32 +08:00
"^/dev-api": "", // 发送请求时自动去掉开头
2024-06-24 11:52:30 +08:00
},
2024-06-24 17:43:49 +08:00
onProxyReq: function (proxyReq, req, res, options) {
2024-06-24 11:52:30 +08:00
if (req.body) {
2024-10-21 11:20:32 +08:00
const bodyData = JSON.stringify(req.body);
2024-06-24 11:52:30 +08:00
// incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
2024-10-21 11:20:32 +08:00
proxyReq.setHeader("Content-Type", "application/json");
proxyReq.setHeader("Content-Length", Buffer.byteLength(bodyData));
2024-06-24 11:52:30 +08:00
// stream the content
2024-10-21 11:20:32 +08:00
proxyReq.write(bodyData);
2024-06-24 11:52:30 +08:00
}
2024-10-21 11:20:32 +08:00
},
},
2024-06-24 11:52:30 +08:00
},
2024-10-21 11:20:32 +08:00
before: require("./mock/mock-server.js"),
2024-06-24 11:52:30 +08:00
},
configureWebpack: {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
name: name,
resolve: {
alias: {
2024-10-21 11:20:32 +08:00
"@": resolve("src"),
},
},
2024-06-24 11:52:30 +08:00
},
chainWebpack(config) {
// it can improve the speed of the first screen, it is recommended to turn on preload
// it can improve the speed of the first screen, it is recommended to turn on preload
2024-10-21 11:20:32 +08:00
config.plugin("preload").tap(() => [
2024-06-24 11:52:30 +08:00
{
2024-10-21 11:20:32 +08:00
rel: "preload",
2024-06-24 11:52:30 +08:00
// to ignore runtime.js
// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
2024-10-21 11:20:32 +08:00
include: "initial",
},
]);
2024-06-24 11:52:30 +08:00
// when there are many pages, it will cause too many meaningless requests
2024-10-21 11:20:32 +08:00
config.plugins.delete("prefetch");
2024-06-24 11:52:30 +08:00
// set svg-sprite-loader
2024-10-21 11:20:32 +08:00
config.module.rule("svg").exclude.add(resolve("src/icons")).end();
2024-06-24 11:52:30 +08:00
config.module
2024-10-21 11:20:32 +08:00
.rule("icons")
2024-06-24 11:52:30 +08:00
.test(/\.svg$/)
2024-10-21 11:20:32 +08:00
.include.add(resolve("src/icons"))
2024-06-24 11:52:30 +08:00
.end()
2024-10-21 11:20:32 +08:00
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
2024-06-24 11:52:30 +08:00
.options({
2024-10-21 11:20:32 +08:00
symbolId: "icon-[name]",
2024-06-24 11:52:30 +08:00
})
2024-10-21 11:20:32 +08:00
.end();
2024-06-24 11:52:30 +08:00
2024-10-21 11:20:32 +08:00
config.when(process.env.NODE_ENV !== "development", (config) => {
config
.plugin("ScriptExtHtmlWebpackPlugin")
.after("html")
.use("script-ext-html-webpack-plugin", [
{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/,
},
])
.end();
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: resolve("src/Wangeditor"), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true,
},
},
});
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
config.optimization.runtimeChunk("single");
});
},
};