vue.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const CompressionPlugin = require("compression-webpack-plugin")
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. // vue.config.js
  8. module.exports = {
  9. /*
  10. Vue-cli3:
  11. Crashed when using Webpack `import()` #2463
  12. https://github.com/vuejs/vue-cli/issues/2463
  13. */
  14. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  15. productionSourceMap: false,
  16. //qiankuan打包时放开
  17. //outputDir: "../dist/main",
  18. // 多入口配置
  19. // pages: {
  20. // index: {
  21. // entry: 'src/main.js',
  22. // template: 'public/index.html',
  23. // filename: 'index.html',
  24. // }
  25. // },
  26. //打包app时放开该配置
  27. //publicPath:'/',
  28. configureWebpack: config => {
  29. //生产环境取消 console.log
  30. if (process.env.NODE_ENV === 'production') {
  31. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  32. }
  33. },
  34. chainWebpack: (config) => {
  35. config.plugins.delete('prefetch')
  36. //只保留中文语言包
  37. config.plugin('ContextReplacementPlugin').use(webpack.ContextReplacementPlugin, [/moment[/\\]locale$/, /zh-cn/])
  38. config.resolve.alias
  39. .set('@$', resolve('src'))
  40. .set('@api', resolve('src/api'))
  41. .set('@assets', resolve('src/assets'))
  42. .set('@comp', resolve('src/components'))
  43. .set('@views', resolve('src/views'))
  44. //生产环境,开启js\css压缩
  45. if (process.env.NODE_ENV === 'production') {
  46. config.plugin('compressionPlugin').use(new CompressionPlugin({
  47. test: /\.(js|css|less)$/, // 匹配文件名
  48. threshold: 10240, // 对超过10k的数据压缩
  49. deleteOriginalAssets: false // 不删除源文件
  50. }))
  51. config.plugin('chunkPlugin').use(webpack.optimize.LimitChunkCountPlugin, [{
  52. maxChunks: 5,
  53. minChunkSize: 10000
  54. }])
  55. }
  56. // 配置 webpack 识别 markdown 为普通的文件
  57. config.module
  58. .rule('markdown')
  59. .test(/\.md$/)
  60. .use()
  61. .loader('file-loader')
  62. .end()
  63. // 编译vxe-table包里的es6代码,解决IE11兼容问题
  64. config.module
  65. .rule('vxe')
  66. .test(/\.js$/)
  67. .include
  68. .add(resolve('node_modules/vxe-table'))
  69. .add(resolve('node_modules/vxe-table-plugin-antd'))
  70. .end()
  71. .use()
  72. .loader('babel-loader')
  73. .end()
  74. },
  75. css: {
  76. loaderOptions: {
  77. less: {
  78. modifyVars: {
  79. /* less 变量覆盖,用于自定义 ant design 主题 */
  80. 'primary-color': '#1890FF',
  81. 'link-color': '#1890FF',
  82. 'border-radius-base': '4px',
  83. },
  84. javascriptEnabled: true,
  85. }
  86. }
  87. },
  88. devServer: {
  89. port: 3000,
  90. // hot: true,
  91. // disableHostCheck: true,
  92. // overlay: {
  93. // warnings: false,
  94. // errors: true,
  95. // },
  96. // headers: {
  97. // 'Access-Control-Allow-Origin': '*',
  98. // },
  99. proxy: {
  100. /* '/api': {
  101. target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro', //mock API接口系统
  102. ws: false,
  103. changeOrigin: true,
  104. pathRewrite: {
  105. '/jeecg-boot': '' //默认所有请求都加了jeecg-boot前缀,需要去掉
  106. }
  107. },*/
  108. /* 注意:jeecgboot前端做了改造,此处不需要配置跨域和后台接口(只需要改.env相关配置文件即可)
  109. issues/3462 很多人此处做了配置,导致刷新前端404问题,请一定注意*/
  110. '/jeecg-boot': {
  111. target: 'http://localhost:8080',
  112. ws: false,
  113. changeOrigin: true
  114. },
  115. }
  116. },
  117. lintOnSave: undefined
  118. }