vue.config.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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,
  17. sourceMap: false,
  18. // requireModuleExtension: true,
  19. loaderOptions: {
  20. sass: {
  21. prependData: `@import "@/assets/css/variable.scss";`
  22. }
  23. }
  24. },
  25. chainWebpack: config => {
  26. config.plugin('html').tap(args => {
  27. args[0].title = '黑龙江省哈尔滨市2024年老旧小区改造项目EPC工程总承包(七标段)'
  28. return args
  29. })
  30. // 配置别名
  31. config.resolve.alias.set('@', resolve('src')).set('assets', resolve('src/assets')).set('components', resolve('src/components')).set('views', resolve('src/views')).set('api', resolve('src/api'))
  32. if (process.env.NODE_ENV === 'production') {
  33. // 删除系统默认的splitChunk
  34. config.optimization.delete('splitChunks')
  35. }
  36. },
  37. configureWebpack: config => {
  38. // 给输出的js名称添加hash
  39. config.output.filename = 'static/js/[name].[hash].js'
  40. config.output.chunkFilename = 'static/js/[name].[hash].js'
  41. config.optimization = {
  42. splitChunks: {
  43. cacheGroups: {
  44. // 抽离所有入口的公用资源为一个chunk
  45. common: {
  46. name: 'chunk-common',
  47. chunks: 'initial',
  48. minChunks: 2,
  49. maxInitialRequests: 5,
  50. minSize: 0,
  51. priority: 1,
  52. reuseExistingChunk: true,
  53. enforce: true
  54. },
  55. datav: {
  56. name: 'chunk-datav',
  57. test: /[\\/]node_modules[\\/]@jiaminghi[\\/]data-view[\\/]/,
  58. chunks: 'all',
  59. priority: 4,
  60. reuseExistingChunk: true,
  61. enforce: true
  62. }
  63. }
  64. }
  65. }
  66. },
  67. // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
  68. parallel: require('os').cpus().length > 1,
  69. devServer: {
  70. proxy: {
  71. '/x_program_center': {
  72. target: 'http://www.harbinxiaoshi.cn:8000',
  73. pathRewrite: {
  74. '^/x_program_center': ''
  75. }
  76. }
  77. }
  78. }
  79. }