vue.config.js 3.1 KB

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