vue.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. const path = require("path");
  2. const isProduction = process.env.NODE_ENV === "production";
  3. function resolve(dir) {
  4. return path.join(__dirname, dir);
  5. }
  6. module.exports = {
  7. publicPath: "/",
  8. lintOnSave: true,
  9. productionSourceMap: false,
  10. parallel: require("os").cpus().length > 1,
  11. css: {
  12. extract: isProduction,
  13. sourceMap: false,
  14. loaderOptions: {
  15. sass: {
  16. prependData: `@import "@/assets/css/common.scss";`
  17. }
  18. }
  19. },
  20. devServer: {
  21. port: 9000,
  22. open: false,
  23. compress: false,
  24. overlay: {
  25. warnings: false,
  26. errors: true
  27. },
  28. disableHostCheck: true,
  29. proxy: {
  30. "/dev": {
  31. target: "http://127.0.0.1:8001",
  32. changeOrigin: true,
  33. pathRewrite: {
  34. "^/dev": ""
  35. }
  36. },
  37. "/ap": {
  38. target: "https://admin.cn.utools.club",
  39. changeOrigin: true,
  40. pathRewrite: {
  41. "^/ap": ""
  42. }
  43. },
  44. "/fz": {
  45. target: "http://xfz520231.utools.club",
  46. changeOrigin: true,
  47. pathRewrite: {
  48. "^/fz": ""
  49. }
  50. },
  51. "/oss-upload": {
  52. target: "https://cool-admin-pro.oss-cn-shanghai.aliyuncs.com",
  53. changeOrigin: true,
  54. pathRewrite: {
  55. "^/oss-upload": ""
  56. }
  57. },
  58. "/pro": {
  59. target: "https://show.cool-admin.com",
  60. changeOrigin: true,
  61. pathRewrite: {
  62. "^/pro": "/api"
  63. }
  64. }
  65. }
  66. },
  67. chainWebpack: (config) => {
  68. // svg
  69. config.module.rule("svg").uses.clear();
  70. config.module
  71. .rule("svg-sprite-loader")
  72. .test(/.svg$/)
  73. .exclude.add(/node_modules/)
  74. .end()
  75. .use("svg-sprite-loader")
  76. .loader("svg-sprite-loader")
  77. .options({
  78. symbolId: "[name]"
  79. });
  80. // 去掉元素之间空格
  81. config.module
  82. .rule("vue")
  83. .use("vue-loader")
  84. .loader("vue-loader")
  85. .tap((options) => {
  86. options.compilerOptions.preserveWhitespace = true;
  87. return options;
  88. })
  89. .end();
  90. // 移除 prefetch 插件
  91. config.plugins.delete("prefetch-index");
  92. // 移除 preload 插件,避免加载多余的资源
  93. config.plugins.delete("preload-index");
  94. // 设置别名
  95. config.resolve.alias.set("cool", resolve("cool"));
  96. // 生产模式下
  97. if (isProduction) {
  98. config.performance.set("hints", false);
  99. config.optimization.splitChunks({
  100. chunks: "all",
  101. cacheGroups: {
  102. // 公用模块抽离
  103. common: {
  104. chunks: "initial",
  105. minSize: 0,
  106. minChunks: 2
  107. },
  108. // 第三方库抽离
  109. vendor: {
  110. priority: 1,
  111. test: /node_modules/,
  112. chunks: "initial",
  113. minSize: 0,
  114. minChunks: 2
  115. }
  116. }
  117. });
  118. }
  119. }
  120. };