vue.config.js 3.8 KB

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