vue.config.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const path = require('path')
  2. const CompressionPlugin = require('compression-webpack-plugin')
  3. function resolve (dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. // vue.config.js
  7. module.exports = {
  8. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  9. productionSourceMap: false,
  10. configureWebpack: config => {
  11. // 生产环境取消 console.log
  12. if (process.env.NODE_ENV === 'production') {
  13. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  14. }
  15. },
  16. chainWebpack: (config) => {
  17. config.resolve.alias
  18. .set('@$', resolve('src'))
  19. .set('@api', resolve('src/api'))
  20. .set('@assets', resolve('src/assets'))
  21. .set('@comp', resolve('src/components'))
  22. .set('@views', resolve('src/views'))
  23. // 生产环境,开启js\css压缩
  24. if (process.env.NODE_ENV === 'production') {
  25. config.plugin('compressionPlugin').use(new CompressionPlugin({
  26. test: /\.(js|css|less)$/, // 匹配文件名
  27. threshold: 10240, // 对超过10k的数据压缩
  28. deleteOriginalAssets: false // 删除源文件
  29. }))
  30. }
  31. },
  32. css: {
  33. loaderOptions: {
  34. less: {
  35. modifyVars: {
  36. /* less 变量覆盖,用于自定义 ant design 主题 */
  37. 'primary-color': '#1890FF',
  38. 'link-color': '#1890FF',
  39. 'border-radius-base': '4px'
  40. },
  41. javascriptEnabled: true
  42. }
  43. }
  44. },
  45. devServer: {
  46. port: 80,
  47. proxy: {
  48. '/jshERP-boot': {
  49. target: 'http://localhost:8080', // 请求本地 需要jshERP-boot后台项目
  50. ws: false,
  51. changeOrigin: true
  52. }
  53. }
  54. },
  55. lintOnSave: undefined
  56. }