vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. // 把子应用打包成 umd 库格式
  34. library: {
  35. type: "umd",
  36. name: `${name}`,
  37. },
  38. chunkLoadingGlobal: `webpackJsonp_${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 (url === "/" || url === "/hr" || url === "/hr/" || url === "/hr-pc" || url === "/hr-pc/") {
  60. res.redirect(publicPath);
  61. return;
  62. }
  63. next();
  64. },
  65. });
  66. return middlewares;
  67. },
  68. // 代理跨域的配置
  69. proxy: {
  70. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  71. "/api": {
  72. // target: 'http://192.168.1.3:18086',
  73. // target: 'http://192.168.1.158:18086',
  74. // target: 'http://192.168.1.176:18086',
  75. // target: "http://192.168.1.125:18086",
  76. // target: 'http://192.168.1.251:51005',
  77. // target: 'http://192.168.1.251:18186',
  78. // target: 'http://192.168.1.251:18086', // 服务器
  79. // target: 'http://192.168.1.251:18186',
  80. // target: 'http://192.168.1.3:18086',
  81. // target: 'http://192.168.1.251:18186', // 测试环境
  82. // target: 'http://192.168.1.251:18087',
  83. // target: 'http://192.168.1.116:18086',
  84. // target: 'http://192.168.1.125:18086',
  85. // target: 'http://192.168.1.11:18086', // 开发
  86. // target: 'http://192.168.1.116:18086', // 赵沙金
  87. // target: 'http://aiot.zoomwin.com.cn:51001/api',
  88. // target: 'http://f222326r53.imwork.net',
  89. // target: 'http://aiot.zoomwin.com.cn:51005/api',
  90. target: 'http://192.168.1.147:18086',
  91. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  92. pathRewrite: {
  93. "^/api": "",
  94. },
  95. },
  96. // kkFileView 在线预览(与 WT 一致,本地才能打开 /kkfile/onlinePreview)
  97. "/kkfile": {
  98. target: "http://aiot.zoomwin.com.cn:51001",
  99. changeOrigin: true,
  100. pathRewrite: { "^/kkfile": "/kkfile" },
  101. },
  102. },
  103. headers: {
  104. "Access-Control-Allow-Origin": "*",
  105. },
  106. },
  107. chainWebpack(config) {
  108. config.plugins.delete("prefetch");
  109. // set svg-sprite-loader
  110. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  111. // config.module
  112. // .rule('icons')
  113. // .test(/\.svg$/)
  114. // .include.add(resolve('./src/icons'))
  115. // .end()
  116. // .use('svg-sprite-loader')
  117. // .loader('svg-sprite-loader')
  118. // .options({
  119. // symbolId: 'icon-[name]'
  120. // })
  121. // .end();
  122. config.module.rule("svg").exclude.add(resolve("src/icons")).end();
  123. config.module
  124. .rule("icons")
  125. .test(/\.svg$/)
  126. .include.add(resolve("src/icons"))
  127. .end()
  128. .use("svg-sprite-loader")
  129. .loader("svg-sprite-loader")
  130. .options({
  131. symbolId: "icon-[name]",
  132. })
  133. .end();
  134. if (process.env.NODE_ENV !== "development") {
  135. // gzip 压缩
  136. config.plugin("compressionPlugin").use(
  137. new CompressionWebpackPlugin({
  138. test: /\.(js|css|html)$/,
  139. threshold: 10240,
  140. }),
  141. );
  142. }
  143. },
  144. css: {
  145. loaderOptions: {
  146. // 与 vue-style-loader 的 CommonJS 约定对齐
  147. css: {
  148. esModule: false,
  149. },
  150. sass: { sassOptions },
  151. scss: { sassOptions },
  152. },
  153. },
  154. };