vue.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // gzip 压缩代码
  2. const CompressionPlugin = require('compression-webpack-plugin')
  3. // 打包分析
  4. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  5. // terser-webpack-plugin 可不引入, @vue/cli-service 中已经引入了terser-webpack-plugin
  6. // const TerserPlugin = require('terser-webpack-plugin')
  7. module.exports = {
  8. devServer: {
  9. port: 8092,
  10. open: true,
  11. proxy: {
  12. '/data': {
  13. // target: 'http://10.199.143.126', //生产环境
  14. target: 'http://60.205.177.43', //阿里云
  15. changeOrigin: true,
  16. secure: false,
  17. pathRewrite: {
  18. '^/data': '/data',
  19. },
  20. },
  21. // 绘图服务
  22. '/serve': {
  23. // target: 'http://10.199.143.129:8080', //生产环境
  24. target: 'http://60.205.177.43:8080', //阿里云
  25. changeOrigin: true,
  26. pathRewrite: {
  27. '^/serve': '',
  28. },
  29. },
  30. },
  31. hot: true,
  32. // 关闭esline
  33. overlay: {
  34. warnings: false,
  35. errors: false,
  36. },
  37. },
  38. chainWebpack: (config) => {
  39. const svgRule = config.module.rule('svg')
  40. svgRule.uses.clear()
  41. svgRule
  42. .use('babel-loader')
  43. .loader('babel-loader')
  44. .end()
  45. .use('vue-svg-loader')
  46. .loader('vue-svg-loader')
  47. config.output.filename('static/js/[name].[hash].js').end()
  48. config.output.chunkFilename('static/js/[name].[hash].js').end()
  49. },
  50. lintOnSave: false,
  51. publicPath: '/wandaBmGuideH5',
  52. // 打包名称
  53. outputDir: 'wandaBmGuideH5',
  54. // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  55. assetsDir: 'static',
  56. transpileDependencies: [
  57. '@saga-web', // 指定对第三方依赖包进行babel-polyfill处理
  58. ],
  59. productionSourceMap: false,
  60. // CSS 相关选项
  61. css: {
  62. // 将组件内的 CSS 提取到一个单独的 CSS 文件 (只用在生产环境中)
  63. extract: true,
  64. },
  65. // 配置webpack
  66. configureWebpack: (config) => {
  67. // 生成环境,删除console.log和debugger
  68. // TODO: 1.
  69. if (process.env.NODE_ENV === 'production' && false) {
  70. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true //删除console
  71. config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true //删除 debugger
  72. config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log'] //删除
  73. }
  74. let plugins = [
  75. // 压缩代码
  76. new CompressionPlugin({
  77. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  78. threshold: 10240, // 对超过10k的数据压缩
  79. deleteOriginalAssets: false, // false 不删除源文件 true 删除源文件
  80. }),
  81. ]
  82. // 生产环境打包分析体积 命令 npm run build --report 或者 yarn build --report
  83. if (process.env.NODE_ENV === 'production' && (process.env.npm_config_report || process.env.npm_config_argv.indexOf('--report') !== -1)) {
  84. plugins.push(new BundleAnalyzerPlugin())
  85. }
  86. return {
  87. plugins,
  88. }
  89. },
  90. }