vue.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const path = require('path')
  2. const rm = require('rimraf')
  3. // 监听打包完成
  4. const FileManagerPlugin = require('filemanager-webpack-plugin')
  5. const date = new Date()
  6. const y = date.getFullYear()
  7. const m = (date.getMonth() + 1).toString().padStart(2, '0')
  8. const d = date.getDate().toString().padStart(2, '0')
  9. const h = date.getHours().toString().padStart(2, '0')
  10. const timestamp = `?${y}${m}${d}${h}`
  11. const env = ['develop', undefined].includes(process.env.BUILD_ENV) ? require('./config/dev.env') : (process.env.BUILD_ENV === 'release' ? require('./config/release.env') : require('./config/prod.env'))
  12. const resolve = (dir) => {
  13. return path.join(__dirname, dir)
  14. }
  15. const addStyleResource = (rule) => {
  16. rule.use('style-resource')
  17. .loader('style-resources-loader')
  18. .options({
  19. patterns: [
  20. path.resolve(__dirname, './src/assets/styles/variable.scss')
  21. ]
  22. })
  23. }
  24. if (process.env.NODE_ENV !== 'development') {
  25. rm(resolve('./dist'), err => {
  26. if (err) throw err
  27. })
  28. }
  29. module.exports = {
  30. publicPath: '/',
  31. outputDir: './dist', // 构建文件目录,默认dist
  32. filenameHashing: false,
  33. // lintOnSave: false,
  34. productionSourceMap: process.env.BUILD_ENV === 'develop',
  35. devServer: {
  36. hot: true,
  37. hotOnly: true,
  38. host: '0.0.0.0',
  39. port: 8080,
  40. open: true,
  41. clientLogLevel: 'warning',
  42. proxy: {
  43. '/proxycodedreamit': {
  44. target: 'http://test-pay.codedreamit.com',
  45. ws: true,
  46. changeOrigin: true,
  47. pathRewrite: {
  48. '^/proxycodedreamit': ''
  49. }
  50. },
  51. '/api': {
  52. target: 'http://test-daogou.codedreamit.com',
  53. ws: true,
  54. changeOrigin: true,
  55. pathRewrite: {
  56. '^/api': '/api'
  57. }
  58. },
  59. '/sell': {
  60. target: 'http://ustbhuangyi.com',
  61. ws: true,
  62. changeOrigin: true,
  63. pathRewrite: {
  64. '^/sell': '/sell'
  65. }
  66. }
  67. },
  68. overlay: {
  69. warnings: false,
  70. errors: false
  71. },
  72. before (app) {
  73. }
  74. },
  75. configureWebpack: {
  76. resolve: {
  77. alias: {
  78. '@': resolve('src')
  79. }
  80. },
  81. output: {
  82. filename: 'js/[name].[hash].js' + timestamp,
  83. chunkFilename: 'js/[name].[hash].js' + timestamp
  84. },
  85. plugins: process.env.NODE_ENV !== 'development' ? [
  86. new FileManagerPlugin({
  87. onEnd: [
  88. {
  89. delete: ['./dist/*/favicon.ico', './dist/*/index.html']
  90. }
  91. ]
  92. })
  93. ] : [],
  94. performance: {
  95. hints: 'warning',
  96. // 入口起点的最大体积 整数类型(以字节为单位)
  97. maxEntrypointSize: 5000000,
  98. // 生成文件的最大体积 整数类型(以字节为单位 300k)
  99. maxAssetSize: 3000000,
  100. // 只给出 js 文件的性能提示
  101. assetFilter: function (assetFilename) {
  102. return assetFilename.endsWith('.js')
  103. }
  104. }
  105. },
  106. chainWebpack: config => {
  107. const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
  108. types.forEach(type => addStyleResource(config.module.rule('scss').oneOf(type)))
  109. config.plugin('define').tap(args => {
  110. args[0]['process.env'] = Object.assign({}, args[0]['process.env'], env)
  111. return args
  112. })
  113. config.plugins.delete('preload')
  114. config.plugins.delete('prefetch')
  115. },
  116. css: process.env.NODE_ENV !== 'development' ? {
  117. extract: {
  118. filename: 'css/[name].[hash].css' + timestamp,
  119. chunkFilename: 'css/[name].[hash].css' + timestamp,
  120. ignoreOrder: true
  121. },
  122. sourceMap: false
  123. } : {}
  124. }