You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
4.8 KiB
JavaScript
173 lines
4.8 KiB
JavaScript
"use strict";
|
|
const path = require("path");
|
|
const defaultSettings = require("./settings.js");
|
|
|
|
const ENV = process.env.NODE_ENV.toLowerCase();
|
|
console.log(ENV);
|
|
const API_CONFIG = defaultSettings.API[ENV] || {};
|
|
console.log(API_CONFIG);
|
|
// https://cli.vuejs.org/guide/mode-and-env.html#using-env-variables-in-client-side-code
|
|
|
|
Object.keys(API_CONFIG).forEach((key) => {
|
|
if (!key.startsWith("VUE_APP_")) {
|
|
throw new Error(`${key} 必须以【VUE_APP_】开始;API.${ENV}.${key}`);
|
|
}
|
|
process.env[key] = API_CONFIG[key];
|
|
});
|
|
|
|
function resolve(dir) {
|
|
return path.join(__dirname, dir);
|
|
}
|
|
|
|
const name = defaultSettings.title || "Huatek Frontend Template";
|
|
|
|
const port = process.env.port || process.env.npm_config_port || 9528; // 端口
|
|
|
|
module.exports = {
|
|
publicPath: "/",
|
|
outputDir: "dist",
|
|
assetsDir: "static",
|
|
// lintOnSave: true,
|
|
lintOnSave: false,
|
|
// lintOnSave: process.env.NODE_ENV === 'development',
|
|
productionSourceMap: false,
|
|
devServer: {
|
|
compress: true,
|
|
disableHostCheck: true,
|
|
port: port,
|
|
host: "0.0.0.0",
|
|
open: true,
|
|
overlay: {
|
|
warnings: false,
|
|
erors: true,
|
|
},
|
|
proxy: {
|
|
[process.env.VUE_APP_BASE_API]: {
|
|
// target: `http://192.168.1.161:${port}/mock`,
|
|
target: `http://192.168.1.190:92/`,
|
|
changeOrigin: true,
|
|
// logger: 'debug',
|
|
pathRewrite: {
|
|
["^" + process.env.VUE_APP_BASE_API]: "/jkpg-api",
|
|
},
|
|
},
|
|
|
|
// 加载莫模型
|
|
[process.env.VUE_APP_MODEL_API]: {
|
|
// target: `http://127.0.0.1:8082/`,
|
|
// cac token获取ip
|
|
target: `http://192.168.1.190:92/`,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
["^" + process.env.VUE_APP_MODEL_API]: "",
|
|
},
|
|
// logLevel: 'debug'
|
|
},
|
|
// 一键登录升级振动
|
|
"/sysLoginRemoteController/login": {
|
|
// target: `http://192.168.1.12:8081/`,
|
|
// target: `http://192.168.41.24:8081/`,
|
|
// target: `http://192.168.1.24:8081/`,
|
|
target: `http://192.168.135.81:8081/`,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
"^/api": "",
|
|
},
|
|
// logLevel: 'debug'
|
|
},
|
|
// 一键登录CAC
|
|
"/cacRemote/login": {
|
|
// target: `http://127.0.0.1:8082/`,
|
|
// cac token获取ip
|
|
target: `http://192.168.145.147:8082/`,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
"^/api": "",
|
|
},
|
|
// logLevel: 'debug'
|
|
},
|
|
},
|
|
after: require("./mock/mock-server.js"),
|
|
},
|
|
configureWebpack: {
|
|
name: name,
|
|
resolve: {
|
|
alias: {
|
|
"@": resolve("src"),
|
|
},
|
|
},
|
|
},
|
|
chainWebpack(config) {
|
|
config.plugins.delete("preload");
|
|
config.plugins.delete("prefetch");
|
|
|
|
// set svg-sprite-loader
|
|
config.module.rule("svg").exclude.add(resolve("src/assets/icons")).end();
|
|
config.module
|
|
.rule("icons")
|
|
.test(/\.svg$/)
|
|
.include.add(resolve("src/assets/icons"))
|
|
.end()
|
|
.use("svg-sprite-loader")
|
|
.loader("svg-sprite-loader")
|
|
.options({
|
|
symbolId: "icon-[name]",
|
|
})
|
|
.end();
|
|
|
|
// set preserveWhitespace
|
|
config.module
|
|
.rule("vue")
|
|
.use("vue-loader")
|
|
.loader("vue-loader")
|
|
.tap((options) => {
|
|
options.compilerOptions.preserveWhitespace = true;
|
|
return options;
|
|
})
|
|
.end();
|
|
|
|
config
|
|
// https://webpack.js.org/configuration/devtool/#development
|
|
.when(process.env.NODE_ENV === "development", (config) =>
|
|
config.devtool("cheap-module-eval-source-map")
|
|
);
|
|
|
|
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/components"), // can customize your rules
|
|
minChunks: 3, // minimum common number
|
|
priority: 5,
|
|
reuseExistingChunk: true,
|
|
},
|
|
},
|
|
});
|
|
config.optimization.runtimeChunk("single");
|
|
});
|
|
},
|
|
};
|