vue.config.js 3.3 KB

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