vue.config.js 3.2 KB

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