vue.config.js 2.2 KB

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