vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  2. const { transformElementScss } = require("ele-admin/lib/utils/dynamic-theme");
  3. const path = require("path");
  4. const { name } = require("./package.json");
  5. function resolve(dir) {
  6. return path.join(__dirname, dir);
  7. }
  8. // 与 EOM(/eos)、WT(/wt) 一致:静态资源部署在短路径 /hr,乾坤路由前缀才是 /page-hr
  9. const publicPath = process.env.VUE_APP_PUBLIC_PATH || "/hr";
  10. // element-ui / ele-admin 仍使用 Sass @import,静音 Dart Sass 弃用警告
  11. const sassOptions = {
  12. outputStyle: "expanded",
  13. importer: transformElementScss(),
  14. quietDeps: true,
  15. silenceDeprecations: [
  16. "import",
  17. "global-builtin",
  18. "color-functions",
  19. "slash-div",
  20. "legacy-js-api",
  21. ],
  22. };
  23. module.exports = {
  24. publicPath,
  25. lintOnSave: false,
  26. outputDir: "dist",
  27. productionSourceMap: false,
  28. configureWebpack: {
  29. performance: {
  30. maxAssetSize: 2000000,
  31. maxEntrypointSize: 2000000,
  32. },
  33. output: {
  34. // 与 EOM/WT 一致:子应用打包成 umd 库格式
  35. library: {
  36. type: "umd",
  37. name: `${name}`,
  38. },
  39. chunkLoadingGlobal: `webpackJsonp_${name}`,
  40. },
  41. // Vue2 + vue-style-loader:样式靠副作用注入,不导出 default;
  42. // Webpack5 会对 `import style0 from ...` 报 missing export,可安全忽略
  43. ignoreWarnings: [
  44. {
  45. message:
  46. /export ['"]default['"] \(imported as ['"]style\d+['"]\) was not found/,
  47. },
  48. ],
  49. },
  50. devServer: {
  51. open: [publicPath.endsWith("/") ? publicPath : `${publicPath}/`],
  52. historyApiFallback: {
  53. index: path.posix.join(
  54. publicPath.endsWith("/") ? publicPath : `${publicPath}/`,
  55. "index.html",
  56. ),
  57. },
  58. setupMiddlewares(middlewares) {
  59. middlewares.unshift({
  60. name: "redirect-to-app",
  61. middleware(req, res, next) {
  62. const url = (req.url || "").split("?")[0];
  63. const appIndex = publicPath.endsWith("/")
  64. ? publicPath
  65. : `${publicPath}/`;
  66. if (
  67. url === "/" ||
  68. url === "/page-hr" ||
  69. url === "/page-hr/" ||
  70. url === "/hr-pc" ||
  71. url === "/hr-pc/"
  72. ) {
  73. res.redirect(appIndex);
  74. return;
  75. }
  76. next();
  77. },
  78. });
  79. return middlewares;
  80. },
  81. proxy: {
  82. "/api": {
  83. target: "http://192.168.1.147:18086",
  84. changeOrigin: true,
  85. pathRewrite: {
  86. "^/api": "",
  87. },
  88. },
  89. "/kkfile": {
  90. target: "http://aiot.zoomwin.com.cn:51001",
  91. changeOrigin: true,
  92. pathRewrite: { "^/kkfile": "/kkfile" },
  93. },
  94. },
  95. headers: {
  96. "Access-Control-Allow-Origin": "*",
  97. },
  98. },
  99. chainWebpack(config) {
  100. config.plugins.delete("prefetch");
  101. config.module.rule("svg").exclude.add(resolve("src/icons")).end();
  102. config.module
  103. .rule("icons")
  104. .test(/\.svg$/)
  105. .include.add(resolve("src/icons"))
  106. .end()
  107. .use("svg-sprite-loader")
  108. .loader("svg-sprite-loader")
  109. .options({
  110. symbolId: "icon-[name]",
  111. })
  112. .end();
  113. if (process.env.NODE_ENV !== "development") {
  114. config.plugin("compressionPlugin").use(
  115. new CompressionWebpackPlugin({
  116. test: /\.(js|css|html)$/,
  117. threshold: 10240,
  118. }),
  119. );
  120. }
  121. },
  122. css: {
  123. loaderOptions: {
  124. css: {
  125. esModule: false,
  126. },
  127. sass: { sassOptions },
  128. scss: { sassOptions },
  129. },
  130. },
  131. };