vue.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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': '#1890FF',
  63. 'link-color': '#1890FF',
  64. 'border-radius-base': '4px',
  65. },
  66. javascriptEnabled: true,
  67. }
  68. }
  69. },
  70. devServer: {
  71. port: 3000,
  72. proxy: {
  73. /* '/api': {
  74. target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro', //mock API接口系统
  75. ws: false,
  76. changeOrigin: true,
  77. pathRewrite: {
  78. '/jeecg-boot': '' //默认所有请求都加了jeecg-boot前缀,需要去掉
  79. }
  80. },*/
  81. '/jeecg-boot': {
  82. target: 'http://localhost:8080', //请求本地 需要jeecg-boot后台项目
  83. ws: false,
  84. changeOrigin: true
  85. },
  86. }
  87. },
  88. lintOnSave: undefined
  89. }