vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /*
  9. Vue-cli3:
  10. Crashed when using Webpack `import()` #2463
  11. https://github.com/vuejs/vue-cli/issues/2463
  12. */
  13. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  14. productionSourceMap: false,
  15. // 打包app时放开该配置
  16. // publicPath:'./',
  17. configureWebpack: config => {
  18. // 生产环境取消 console.log
  19. if (process.env.NODE_ENV === 'production') {
  20. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  21. }
  22. },
  23. chainWebpack: (config) => {
  24. config.resolve.alias
  25. .set('@$', resolve('src'))
  26. .set('@api', resolve('src/api'))
  27. .set('@assets', resolve('src/assets'))
  28. .set('@comp', resolve('src/components'))
  29. .set('@views', resolve('src/views'))
  30. //生产环境,开启js\css压缩
  31. if (process.env.NODE_ENV === 'production') {
  32. config.plugin('compressionPlugin').use(new CompressionPlugin({
  33. test: /\.(js|css|less)$/, // 匹配文件名
  34. threshold: 10240, // 对超过10k的数据压缩
  35. deleteOriginalAssets: false // 不删除源文件
  36. }))
  37. }
  38. // 配置 webpack 识别 markdown 为普通的文件
  39. config.module
  40. .rule('markdown')
  41. .test(/\.md$/)
  42. .use()
  43. .loader('file-loader')
  44. .end()
  45. // 编译vxe-table包里的es6代码,解决IE11兼容问题
  46. config.module
  47. .rule('vxe')
  48. .test(/\.js$/)
  49. .include
  50. .add(resolve('node_modules/vxe-table'))
  51. .add(resolve('node_modules/vxe-table-plugin-antd'))
  52. .end()
  53. .use()
  54. .loader('babel-loader')
  55. .end()
  56. },
  57. css: {
  58. loaderOptions: {
  59. less: {
  60. modifyVars: {
  61. /* less 变量覆盖,用于自定义 ant design 主题 */
  62. 'primary-color': '#FA541C',
  63. 'link-color': '#FA541C',
  64. 'border-radius-base': '4px',
  65. },
  66. javascriptEnabled: true,
  67. }
  68. }
  69. },
  70. devServer: {
  71. host: '0.0.0.0', // 新增这一行,允许所有网络接口访问
  72. disableHostCheck: true,
  73. port: 21755,
  74. proxy: {
  75. /* '/api': {
  76. target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro', //mock API接口系统
  77. ws: false,
  78. changeOrigin: true,
  79. pathRewrite: {
  80. '/jeecg-boot': '' //默认所有请求都加了jeecg-boot前缀,需要去掉
  81. }
  82. },*/
  83. '/jeecg-boot': {
  84. target: 'http://localhost:8080', //请求本地 需要jeecg-boot后台项目
  85. ws: false,
  86. changeOrigin: true
  87. },
  88. '/fileDownload': {
  89. target: 'http://anzexian.oss-cn-shenzhen.aliyuncs.com/',
  90. ws: true,
  91. changeOrigin: true,
  92. pathRewrite: {
  93. '/fileDownload': ''
  94. }
  95. },
  96. }
  97. },
  98. lintOnSave: undefined
  99. }