武汉四维h5程序,基于达闼设备,单独分开
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

133 satır
4.7 KiB

  1. const ImageminPlugin = require("imagemin-webpack-plugin").default;
  2. const ImageminMozjpeg = require("imagemin-mozjpeg");
  3. const ImageminWebpPlugin = require("imagemin-webp-webpack-plugin");
  4. const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  5. const CompressionPlugin = require("compression-webpack-plugin");
  6. const CopyPlugin = require("copy-webpack-plugin");
  7. module.exports = {
  8. productionSourceMap: false,
  9. lintOnSave: process.env.NODE_ENV === "development",
  10. configureWebpack: (config) => {
  11. const plugins = [
  12. new ImageminPlugin({
  13. test: /\.(jpe?g|png|gif|svg)$/i,
  14. optipng: {
  15. // imagemin-optipng
  16. optimizationLevel: 3 // 0~7
  17. },
  18. pngquant: null, // imagemin-pngquant
  19. gifsicle: {
  20. // imagemin-gifsicle
  21. optimizationLevel: 1 // 1~3
  22. },
  23. svgo: {}, // imagemin-svgo
  24. jpegtran: null, // imagemin-jpegtran
  25. plugins: [
  26. // imagemin-mozjpeg
  27. ImageminMozjpeg({
  28. quality: 75
  29. })
  30. ]
  31. })
  32. ];
  33. if (process.env.NODE_ENV !== "development") {
  34. plugins.push(
  35. new ImageminWebpPlugin({
  36. config: [
  37. {
  38. test: /\.(jpe?g)$/,
  39. options: {
  40. quality: 75
  41. }
  42. },
  43. {
  44. test: /\.(png|gif|svg)$/,
  45. options: {
  46. quality: 85
  47. }
  48. }
  49. ],
  50. overrideExtension: false,
  51. detailedLogs: false,
  52. silent: false,
  53. strict: false
  54. })
  55. );
  56. plugins.push(
  57. new CompressionPlugin({
  58. test: /\.(js|\.html|\.css|\.json)$/,
  59. algorithm: "gzip",
  60. threshold: 10240,
  61. minRatio: 0.8
  62. })
  63. );
  64. }
  65. if (process.env.ANALYZER) {
  66. plugins.push(
  67. new BundleAnalyzerPlugin({
  68. // 可视化分析打包后输出的Bundle体积大小
  69. analyzerMode: "disabled",
  70. generateStatsFile: true,
  71. statsOptions: { source: false }
  72. })
  73. );
  74. }
  75. config.plugins = [...config.plugins, ...plugins];
  76. },
  77. chainWebpack: (config) => {
  78. if (config.plugins.has("copy")) {
  79. config.plugin("copy").tap((args) => {
  80. args[0][0].ignore.push("static/json/*.json");
  81. return args;
  82. });
  83. }
  84. // // 小于10kb的图片资源才进行Base64编码内联,默认是4k
  85. // config.module
  86. // .rule("images")
  87. // .test(/\.(jpe?g|png|gif|svg|webp)(\?.*)?$/)
  88. // .use("url-loader")
  89. // .loader("url-loader")
  90. // .tap((options) => Object.assign(options, { limit: 10240 }));
  91. },
  92. css: {
  93. loaderOptions: {
  94. scss: {
  95. prependData: `@import "@/styles/dimens.scss";`
  96. }
  97. }
  98. },
  99. devServer: {
  100. // http2: true,
  101. // https: true,
  102. // host: "localhost", //前端服务启动后的访问ip,默认为localhost, host和port组成了前端服务启动后的访问入口。
  103. https: false,
  104. open: true,
  105. proxy: {
  106. "/nuodi": {
  107. target: "https://lecooai.knowdee.com/sdk/api/v1/dialog/chat", //匹配到要代理的上下文后,将上下文前面的地址替换为此代理地址
  108. changeOrigin: true, //是否跨域
  109. pathRewrite: {
  110. "^/nuodi": "/" //拦截到的上下文重写,这里可以将 kweb 重写为空或者其它值,因为我不需要重写,所以这里这么配置。
  111. }
  112. },
  113. "/srv": {
  114. target: "https://ai.lecooai.com", //匹配到要代理的上下文后,将上下文前面的地址替换为此代理地址
  115. changeOrigin: true, //是否跨域
  116. pathRewrite: {
  117. "^/srv": "/" //拦截到的上下文重写,这里可以将 kweb 重写为空或者其它值,因为我不需要重写,所以这里这么配置。
  118. }
  119. }
  120. },
  121. overlay: {
  122. // warnings: true,
  123. errors: true
  124. }
  125. }
  126. };