vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* eslint-disable @typescript-eslint/camelcase */
  2. // gzip 压缩代码
  3. const CompressionPlugin = require("compression-webpack-plugin");
  4. // 打包分析
  5. const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  6. // terser-webpack-plugin 可不引入, @vue/cli-service 中已经引入了terser-webpack-plugin
  7. // const TerserPlugin = require('terser-webpack-plugin')
  8. module.exports = {
  9. devServer: {
  10. open: true,
  11. proxy: {
  12. "/labsl": {
  13. // target: "http://60.205.177.43:28888",
  14. target: "http://192.168.64.17:28888",
  15. changeOrigin: true,
  16. secure: false,
  17. },
  18. "/meiku": {
  19. // target: "http://60.205.177.43:28888",
  20. target: "http://192.168.64.17:28888",
  21. changeOrigin: true,
  22. secure: false,
  23. },
  24. "/datacenter": {
  25. // target: "http://60.205.177.43:28888",
  26. target: "http://192.168.64.17:28888",
  27. changeOrigin: true,
  28. secure: false,
  29. },
  30. "/equip-component": {
  31. // target: "http://60.205.177.43:28888",
  32. target: "http://192.168.64.17:28888",
  33. changeOrigin: true,
  34. secure: false,
  35. },
  36. // 图片服务器
  37. "/image-service": {
  38. target: "http://39.97.179.199:8891",
  39. changeOrigin: true,
  40. secure: false,
  41. pathRewrite: {
  42. "^/image-service": "/image-service/",
  43. },
  44. },
  45. },
  46. // 关闭esline
  47. overlay: {
  48. warnings: false,
  49. errors: false,
  50. },
  51. },
  52. chainWebpack: (config) => {
  53. config.output.filename("static/js/[name].[hash].js").end();
  54. config.output.chunkFilename("static/js/[name].[hash].js").end();
  55. },
  56. lintOnSave: false,
  57. publicPath: "/persagyPlan",
  58. // 打包名称
  59. outputDir: "persagyPlan",
  60. // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  61. assetsDir: "static",
  62. transpileDependencies: [
  63. "@persagy-web", // 指定对第三方依赖包进行babel-polyfill处理
  64. ],
  65. productionSourceMap: false,
  66. // CSS 相关选项
  67. css: {
  68. // 将组件内的 CSS 提取到一个单独的 CSS 文件 (只用在生产环境中)
  69. extract: true,
  70. },
  71. // 配置webpack
  72. configureWebpack: (config) => {
  73. // 生成环境,删除console.log和debugger
  74. if (process.env.VUE_Plan_RealEnv === "production") {
  75. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true; //删除console
  76. config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true; //删除 debugger
  77. config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ["console.log"]; //删除
  78. }
  79. const plugins = [
  80. // 压缩代码
  81. new CompressionPlugin({
  82. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  83. threshold: 10240, // 对超过10k的数据压缩
  84. deleteOriginalAssets: process.env.NODE_ENV === "production", // false 不删除源文件 true 删除源文件
  85. }),
  86. ];
  87. // 生产环境打包分析体积 命令 npm run build --report 或者 yarn build --report
  88. if (process.env.NODE_ENV === "production" && (process.env.npm_config_report || process.env.npm_config_argv.indexOf("--report") !== -1)) {
  89. plugins.push(new BundleAnalyzerPlugin());
  90. }
  91. return {
  92. plugins,
  93. };
  94. },
  95. // chainWebpack:config =>{
  96. // config.module.rule('svg-sprite')
  97. // .use('svgo-loader')
  98. // .loader('svgo-loader')
  99. // }
  100. };