vue.config.js 2.6 KB

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