vue.config.js 3.5 KB

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