vue.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. "/test": {
  38. target: "https://admin.cn.utools.club",
  39. changeOrigin: true,
  40. pathRewrite: {
  41. "^/test": ""
  42. }
  43. },
  44. "/oss-upload": {
  45. target: "https://cool-admin-pro.oss-cn-shanghai.aliyuncs.com",
  46. changeOrigin: true,
  47. pathRewrite: {
  48. "^/oss-upload": ""
  49. }
  50. },
  51. "/pro": {
  52. target: "https://show.cool-admin.com",
  53. changeOrigin: true,
  54. pathRewrite: {
  55. "^/pro": "/api"
  56. }
  57. }
  58. }
  59. },
  60. chainWebpack: (config) => {
  61. // svg
  62. config.module.rule("svg").uses.clear();
  63. config.module
  64. .rule("svg-sprite-loader")
  65. .test(/.svg$/)
  66. .exclude.add(/node_modules/)
  67. .end()
  68. .use("svg-sprite-loader")
  69. .loader("svg-sprite-loader")
  70. .options({
  71. symbolId: "[name]"
  72. });
  73. // 去掉元素之间空格
  74. config.module
  75. .rule("vue")
  76. .use("vue-loader")
  77. .loader("vue-loader")
  78. .tap((options) => {
  79. options.compilerOptions.preserveWhitespace = true;
  80. return options;
  81. })
  82. .end();
  83. // 移除 prefetch 插件
  84. config.plugins.delete("prefetch-index");
  85. // 移除 preload 插件,避免加载多余的资源
  86. config.plugins.delete("preload-index");
  87. // 设置别名
  88. config.resolve.alias.set("cool", resolve("cool"));
  89. // 生产模式下
  90. if (isProduction) {
  91. config.performance.set("hints", false);
  92. config.optimization.splitChunks({
  93. chunks: "all",
  94. cacheGroups: {
  95. // 公用模块抽离
  96. common: {
  97. chunks: "initial",
  98. minSize: 0,
  99. minChunks: 2
  100. },
  101. // 第三方库抽离
  102. vendor: {
  103. priority: 1,
  104. test: /node_modules/,
  105. chunks: "initial",
  106. minSize: 0,
  107. minChunks: 2
  108. }
  109. }
  110. });
  111. }
  112. }
  113. };