vue.config.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. const publicPath = process.env.VUE_APP_PUBLIC_PATH || "/page-hr/";
  9. // element-ui / ele-admin 仍使用 Sass @import,静音 Dart Sass 弃用警告
  10. const sassOptions = {
  11. outputStyle: "expanded",
  12. importer: transformElementScss(),
  13. quietDeps: true,
  14. silenceDeprecations: [
  15. "import",
  16. "global-builtin",
  17. "color-functions",
  18. "slash-div",
  19. "legacy-js-api",
  20. ],
  21. };
  22. module.exports = {
  23. publicPath,
  24. lintOnSave: false,
  25. outputDir: "dist",
  26. productionSourceMap: false,
  27. configureWebpack: {
  28. performance: {
  29. maxAssetSize: 2000000,
  30. maxEntrypointSize: 2000000,
  31. },
  32. output: {
  33. // qiankun 子应用:打包成 umd,并避免全局对象在严格模式下异常
  34. library: `${name}-[name]`,
  35. libraryTarget: "umd",
  36. chunkLoadingGlobal: `webpackJsonp_${name}`,
  37. globalObject: "window",
  38. uniqueName: name,
  39. },
  40. // Vue2 + vue-style-loader:样式靠副作用注入,不导出 default;
  41. // Webpack5 会对 `import style0 from ...` 报 missing export,可安全忽略
  42. ignoreWarnings: [
  43. {
  44. message:
  45. /export ['"]default['"] \(imported as ['"]style\d+['"]\) was not found/,
  46. },
  47. ],
  48. },
  49. devServer: {
  50. open: [publicPath],
  51. historyApiFallback: {
  52. index: path.posix.join(publicPath, "index.html"),
  53. },
  54. setupMiddlewares(middlewares) {
  55. middlewares.unshift({
  56. name: "redirect-to-app",
  57. middleware(req, res, next) {
  58. const url = (req.url || "").split("?")[0];
  59. if (
  60. url === "/" ||
  61. url === "/hr" ||
  62. url === "/hr/" ||
  63. url === "/hr-pc" ||
  64. url === "/hr-pc/"
  65. ) {
  66. res.redirect(publicPath);
  67. return;
  68. }
  69. next();
  70. },
  71. });
  72. return middlewares;
  73. },
  74. // 代理跨域的配置
  75. proxy: {
  76. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  77. "/api": {
  78. // target: 'http://192.168.1.3:18086',
  79. // target: 'http://192.168.1.158:18086',
  80. // target: 'http://192.168.1.176:18086',
  81. // target: "http://192.168.1.125:18086",
  82. // target: 'http://192.168.1.251:51005',
  83. // target: 'http://192.168.1.251:18186',
  84. // target: 'http://192.168.1.251:18086', // 服务器
  85. // target: 'http://192.168.1.251:18186',
  86. // target: 'http://192.168.1.3:18086',
  87. // target: 'http://192.168.1.251:18186', // 测试环境
  88. // target: 'http://192.168.1.251:18087',
  89. // target: 'http://192.168.1.116:18086',
  90. // target: 'http://192.168.1.125:18086',
  91. // target: 'http://192.168.1.11:18086', // 开发
  92. // target: 'http://192.168.1.116:18086', // 赵沙金
  93. // target: 'http://aiot.zoomwin.com.cn:51001/api',
  94. // target: 'http://f222326r53.imwork.net',
  95. // target: 'http://aiot.zoomwin.com.cn:51005/api',
  96. target: "http://192.168.1.147:18086",
  97. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  98. pathRewrite: {
  99. "^/api": "",
  100. },
  101. },
  102. // kkFileView 在线预览(与 WT 一致,本地才能打开 /kkfile/onlinePreview)
  103. "/kkfile": {
  104. target: "http://aiot.zoomwin.com.cn:51001",
  105. changeOrigin: true,
  106. pathRewrite: { "^/kkfile": "/kkfile" },
  107. },
  108. },
  109. headers: {
  110. "Access-Control-Allow-Origin": "*",
  111. },
  112. },
  113. chainWebpack(config) {
  114. config.plugins.delete("prefetch");
  115. // qiankun:入口 js 需落在 body,避免 head+defer 导致生命周期读取失败
  116. config.plugin("html").tap((args) => {
  117. args[0].inject = "body";
  118. return args;
  119. });
  120. config.module.rule("svg").exclude.add(resolve("src/icons")).end();
  121. config.module
  122. .rule("icons")
  123. .test(/\.svg$/)
  124. .include.add(resolve("src/icons"))
  125. .end()
  126. .use("svg-sprite-loader")
  127. .loader("svg-sprite-loader")
  128. .options({
  129. symbolId: "icon-[name]",
  130. })
  131. .end();
  132. if (process.env.NODE_ENV !== "development") {
  133. // gzip 压缩
  134. config.plugin("compressionPlugin").use(
  135. new CompressionWebpackPlugin({
  136. test: /\.(js|css|html)$/,
  137. threshold: 10240,
  138. }),
  139. );
  140. }
  141. },
  142. css: {
  143. loaderOptions: {
  144. // 与 vue-style-loader 的 CommonJS 约定对齐
  145. css: {
  146. esModule: false,
  147. },
  148. sass: { sassOptions },
  149. scss: { sassOptions },
  150. },
  151. },
  152. };