vue.config.js 3.3 KB

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