vue.config.js 3.0 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. // 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: '/tdzcxx/',
  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: '/tdzcxx/',
  27. configureWebpack: config => {
  28. config.externals = {
  29. BMap: 'BMap'
  30. }
  31. // 生产环境取消 console.log
  32. if (process.env.NODE_ENV === 'production') {
  33. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  34. }
  35. },
  36. chainWebpack: (config) => {
  37. config.resolve.alias
  38. .set('@$', resolve('src'))
  39. .set('@api', resolve('src/api'))
  40. .set('@assets', resolve('src/assets'))
  41. .set('@comp', resolve('src/components'))
  42. .set('@views', resolve('src/views'))
  43. // 生产环境,开启js\css压缩
  44. if (process.env.NODE_ENV === 'production') {
  45. config.plugin('compressionPlugin').use(new CompressionPlugin({
  46. test: /\.(js|css|less)$/, // 匹配文件名
  47. threshold: 10240, // 对超过10k的数据压缩
  48. deleteOriginalAssets: false // 不删除源文件
  49. }))
  50. }
  51. // 配置 webpack 识别 markdown 为普通的文件
  52. config.module
  53. .rule('markdown')
  54. .test(/\.md$/)
  55. .use()
  56. .loader('file-loader')
  57. .end()
  58. // 编译vxe-table包里的es6代码,解决IE11兼容问题
  59. config.module
  60. .rule('vxe')
  61. .test(/\.js$/)
  62. .include
  63. .add(resolve('node_modules/vxe-table'))
  64. .add(resolve('node_modules/vxe-table-plugin-antd'))
  65. .end()
  66. .use()
  67. .loader('babel-loader')
  68. .end()
  69. },
  70. css: {
  71. loaderOptions: {
  72. less: {
  73. modifyVars: {
  74. /* less 变量覆盖,用于自定义 ant design 主题 */
  75. // 'primary-color': '#3264ff',
  76. 'primary-color': '#1882ff',
  77. // 'link-color': '#3264ff',
  78. 'link-color': '#1882ff',
  79. 'border-radius-base': '4px'
  80. },
  81. javascriptEnabled: true
  82. }
  83. }
  84. },
  85. devServer: {
  86. port: 3001,
  87. // hot: true,
  88. // disableHostCheck: true,
  89. // overlay: {
  90. // warnings: false,
  91. // errors: true,
  92. // },
  93. // headers: {
  94. // 'Access-Control-Allow-Origin': '*',
  95. // },
  96. proxy: {
  97. // '/geoserver': {
  98. // target: 'http://localhost:8080/geoserver',
  99. // ws: false,
  100. // changeOrigin: true,
  101. // pathRewrite: {
  102. // '^/geoserver': ''
  103. // }
  104. // },
  105. '/jeecg-boot': {
  106. target: 'http://localhost:8080',
  107. ws: false,
  108. changeOrigin: true
  109. }
  110. }
  111. },
  112. lintOnSave: undefined
  113. }