vue.config.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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:28888', //阿里云
  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. config.output.filename('static/js/[name].[hash].js').end()
  40. config.output.chunkFilename('static/js/[name].[hash].js').end()
  41. },
  42. lintOnSave: false,
  43. // 测试包路径修改
  44. publicPath: process.env.VUE_APP_RealEnv === 'alyTest' ? '/wandaBmGuideH5Test' : '/wandaBmGuideH5',
  45. // 打包名称
  46. outputDir: process.env.VUE_APP_RealEnv === 'alyTest' ? 'wandaBmGuideH5Test' : 'wandaBmGuideH5',
  47. // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  48. assetsDir: 'static',
  49. transpileDependencies: [
  50. '@saga-web', // 指定对第三方依赖包进行babel-polyfill处理
  51. ],
  52. productionSourceMap: false,
  53. // CSS 相关选项
  54. css: {
  55. // 将组件内的 CSS 提取到一个单独的 CSS 文件 (只用在生产环境中)
  56. extract: true,
  57. },
  58. // 配置webpack
  59. configureWebpack: (config) => {
  60. // 生成环境,删除console.log和debugger
  61. if (process.env.VUE_APP_RealEnv === 'production') {
  62. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true //删除console
  63. config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true //删除 debugger
  64. config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log'] //删除
  65. }
  66. let plugins = [
  67. // 压缩代码
  68. new CompressionPlugin({
  69. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  70. threshold: 10240, // 对超过10k的数据压缩
  71. deleteOriginalAssets: false, // false 不删除源文件 true 删除源文件
  72. }),
  73. ]
  74. // 生产环境打包分析体积 命令 npm run build --report 或者 yarn build --report
  75. if (process.env.NODE_ENV === 'production' && (process.env.npm_config_report || process.env.npm_config_argv.indexOf('--report') !== -1)) {
  76. plugins.push(new BundleAnalyzerPlugin())
  77. }
  78. return {
  79. plugins,
  80. }
  81. },
  82. }