| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- const CompressionWebpackPlugin = require("compression-webpack-plugin");
- const { transformElementScss } = require("ele-admin/lib/utils/dynamic-theme");
- const path = require("path");
- const { name } = require("./package.json");
- function resolve(dir) {
- return path.join(__dirname, dir);
- }
- // 与 EOM(/eos)、WT(/wt) 一致:静态资源部署在短路径 /hr,乾坤路由前缀才是 /page-hr
- const publicPath = process.env.VUE_APP_PUBLIC_PATH || "/hr";
- // element-ui / ele-admin 仍使用 Sass @import,静音 Dart Sass 弃用警告
- const sassOptions = {
- outputStyle: "expanded",
- importer: transformElementScss(),
- quietDeps: true,
- silenceDeprecations: [
- "import",
- "global-builtin",
- "color-functions",
- "slash-div",
- "legacy-js-api",
- ],
- };
- module.exports = {
- publicPath,
- lintOnSave: false,
- outputDir: "dist",
- productionSourceMap: false,
- configureWebpack: {
- performance: {
- maxAssetSize: 2000000,
- maxEntrypointSize: 2000000,
- },
- output: {
- // 与 EOM/WT 一致:子应用打包成 umd 库格式
- library: {
- type: "umd",
- name: `${name}`,
- },
- chunkLoadingGlobal: `webpackJsonp_${name}`,
- },
- // Vue2 + vue-style-loader:样式靠副作用注入,不导出 default;
- // Webpack5 会对 `import style0 from ...` 报 missing export,可安全忽略
- ignoreWarnings: [
- {
- message:
- /export ['"]default['"] \(imported as ['"]style\d+['"]\) was not found/,
- },
- ],
- },
- devServer: {
- open: [publicPath.endsWith("/") ? publicPath : `${publicPath}/`],
- historyApiFallback: {
- index: path.posix.join(
- publicPath.endsWith("/") ? publicPath : `${publicPath}/`,
- "index.html",
- ),
- },
- setupMiddlewares(middlewares) {
- middlewares.unshift({
- name: "redirect-to-app",
- middleware(req, res, next) {
- const url = (req.url || "").split("?")[0];
- const appIndex = publicPath.endsWith("/")
- ? publicPath
- : `${publicPath}/`;
- if (
- url === "/" ||
- url === "/page-hr" ||
- url === "/page-hr/" ||
- url === "/hr-pc" ||
- url === "/hr-pc/"
- ) {
- res.redirect(appIndex);
- return;
- }
- next();
- },
- });
- return middlewares;
- },
- proxy: {
- "/api": {
- target: "http://192.168.1.147:18086",
- changeOrigin: true,
- pathRewrite: {
- "^/api": "",
- },
- },
- "/kkfile": {
- target: "http://aiot.zoomwin.com.cn:51001",
- changeOrigin: true,
- pathRewrite: { "^/kkfile": "/kkfile" },
- },
- },
- headers: {
- "Access-Control-Allow-Origin": "*",
- },
- },
- chainWebpack(config) {
- config.plugins.delete("prefetch");
- config.module.rule("svg").exclude.add(resolve("src/icons")).end();
- config.module
- .rule("icons")
- .test(/\.svg$/)
- .include.add(resolve("src/icons"))
- .end()
- .use("svg-sprite-loader")
- .loader("svg-sprite-loader")
- .options({
- symbolId: "icon-[name]",
- })
- .end();
- if (process.env.NODE_ENV !== "development") {
- config.plugin("compressionPlugin").use(
- new CompressionWebpackPlugin({
- test: /\.(js|css|html)$/,
- threshold: 10240,
- }),
- );
- }
- },
- css: {
- loaderOptions: {
- css: {
- esModule: false,
- },
- sass: { sassOptions },
- scss: { sassOptions },
- },
- },
- };
|