vue.config.js 3.6 KB

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