vue.config.js 3.5 KB

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