vue.config.js 3.5 KB

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