vue.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // 多入口配置
  16. // pages: {
  17. // index: {
  18. // entry: 'src/main.js',
  19. // template: 'public/index.html',
  20. // filename: 'index.html',
  21. // }
  22. // },
  23. //打包app时放开该配置
  24. //publicPath:'./',
  25. configureWebpack: config => {
  26. //生产环境取消 console.log
  27. if (process.env.NODE_ENV === 'production') {
  28. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  29. }
  30. },
  31. chainWebpack: (config) => {
  32. config.resolve.alias
  33. .set('@$', resolve('src'))
  34. .set('@api', resolve('src/api'))
  35. .set('@assets', resolve('src/assets'))
  36. .set('@comp', resolve('src/components'))
  37. .set('@views', resolve('src/views'))
  38. //生产环境,开启js\css压缩
  39. if (process.env.NODE_ENV === 'production') {
  40. config.plugin('compressionPlugin').use(new CompressionPlugin({
  41. test: /\.(js|css|less)$/, // 匹配文件名
  42. threshold: 10240, // 对超过10k的数据压缩
  43. deleteOriginalAssets: false // 不删除源文件
  44. }))
  45. }
  46. // 配置 webpack 识别 markdown 为普通的文件
  47. config.module
  48. .rule('markdown')
  49. .test(/\.md$/)
  50. .use()
  51. .loader('file-loader')
  52. .end()
  53. // 编译vxe-table包里的es6代码,解决IE11兼容问题
  54. config.module
  55. .rule('vxe')
  56. .test(/\.js$/)
  57. .include
  58. .add(resolve('node_modules/vxe-table'))
  59. .add(resolve('node_modules/vxe-table-plugin-antd'))
  60. .end()
  61. .use()
  62. .loader('babel-loader')
  63. .end()
  64. },
  65. css: {
  66. loaderOptions: {
  67. less: {
  68. modifyVars: {
  69. /* less 变量覆盖,用于自定义 ant design 主题 */
  70. 'primary-color': '#1890FF',
  71. 'link-color': '#1890FF',
  72. 'border-radius-base': '4px',
  73. },
  74. javascriptEnabled: true,
  75. }
  76. }
  77. },
  78. devServer: {
  79. port: 3000,
  80. proxy: {
  81. /* '/api': {
  82. target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro', //mock API接口系统
  83. ws: false,
  84. changeOrigin: true,
  85. pathRewrite: {
  86. '/jeecg-boot': '' //默认所有请求都加了jeecg-boot前缀,需要去掉
  87. }
  88. },*/
  89. '/jeecg-boot': {
  90. target: 'http://localhost:8080', //请求本地 需要jeecg-boot后台项目
  91. ws: false,
  92. changeOrigin: true
  93. },
  94. }
  95. },
  96. lintOnSave: undefined
  97. }