vue.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const path = require("path");
  2. function resolve(dir) {
  3. return path.join(__dirname, dir);
  4. }
  5. module.exports = {
  6. publicPath: './',
  7. outputDir: process.env.VUE_APP_outputDir || 'dist',
  8. assetsDir: 'static',
  9. filenameHashing: true,
  10. lintOnSave: false,
  11. runtimeCompiler: false,
  12. transpileDependencies: [],
  13. productionSourceMap: false,
  14. css: {
  15. // 是否使用css分离插件 ExtractTextPlugin
  16. extract: process.env.NODE_ENV === "production" ? true : false,//是否将组件中的 CSS 提取至一个独立的 CSS 文件中 (而不是动态注入到 JavaScript 中的 inline 代码)。
  17. sourceMap: false,//是否为 CSS 开启 source map。设置为 true 之后可能会影响构建的性能。
  18. loaderOptions: {
  19. sass: {
  20. prependData: `@import "@/assets/css/variable.scss";`
  21. }
  22. },
  23. requireModuleExtension: true,
  24. },
  25. chainWebpack: (config) => {
  26. // 配置别名
  27. config.resolve.alias
  28. .set('@', resolve('src'))
  29. .set('assets', resolve('src/assets'))
  30. .set('assetsBig', resolve('src/pages/big-screen/assets'))
  31. .set('components', resolve('src/components'))
  32. .set('views', resolve('src/views'))
  33. .set('api', resolve('src/api'))
  34. .set('lib', resolve('src/lib'))
  35. if (process.env.NODE_ENV === "production") {
  36. // 删除系统默认的splitChunk
  37. config.optimization.delete("splitChunks");
  38. }
  39. },
  40. configureWebpack: config => {
  41. // 给输出的js名称添加hash
  42. config.output.filename = "static/js/[name].[hash].js";
  43. config.output.chunkFilename = "static/js/[name].[hash].js";
  44. config.optimization = {
  45. splitChunks: {
  46. cacheGroups: {
  47. // 抽离所有入口的公用资源为一个chunk
  48. common: {
  49. name: "chunk-common",
  50. chunks: "initial",
  51. minChunks: 2,
  52. maxInitialRequests: 5,
  53. minSize: 0,
  54. priority: 1,
  55. reuseExistingChunk: true,
  56. enforce: true
  57. },
  58. // 抽离node_modules下的库为一个chunk
  59. // vendors: {
  60. // name: "chunk-vendors",
  61. // test: /[\\/]node_modules[\\/]/,
  62. // chunks: "initial",
  63. // priority: 2,
  64. // reuseExistingChunk: true,
  65. // enforce: true
  66. // },
  67. element: {
  68. name: "chunk-element-ui",
  69. test: /[\\/]node_modules[\\/]element-ui[\\/]/,
  70. chunks: "all",
  71. priority: 3,
  72. reuseExistingChunk: true,
  73. enforce: true
  74. },
  75. yhhtUi: {
  76. name: "chunk-yhht-ui",
  77. test: /[\\/]node_modules[\\/]yhht-ui[\\/]/,
  78. chunks: "all",
  79. priority: 4,
  80. reuseExistingChunk: true,
  81. enforce: true
  82. },
  83. datav: {
  84. name: "chunk-datav",
  85. test: /[\\/]node_modules[\\/]@jiaminghi[\\/]data-view[\\/]/,
  86. chunks: "all",
  87. priority: 4,
  88. reuseExistingChunk: true,
  89. enforce: true
  90. },
  91. }
  92. }
  93. };
  94. },
  95. // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
  96. parallel: require('os').cpus().length > 1,
  97. devServer: {
  98. proxy: {
  99. '/forecast': {
  100. // 预报 天
  101. target: 'http://1.190.195.54:9052',
  102. pathRewrite: {
  103. '^/forecast': ''
  104. }
  105. },
  106. '/weather': {
  107. // 天气
  108. target: 'http://1.190.195.54:20084',
  109. pathRewrite: {
  110. '^/weather': ''
  111. }
  112. },
  113. }
  114. },
  115. pluginOptions: {
  116. }
  117. }