项目里的图片压缩

  chainWebpack: (config) => {
    config.resolve.alias
      .set("components", resolve("src/components"))
      .set("views", resolve("src/views"))
      .set("assets", resolve("src/assets"))
      .set("common", resolve("src/common"));

    // 删除 prefetch 选项:  预加载

    config.plugins.delete("prefetch");
    if (process.env.use_analyzer) {
      // 分析
      config
        .plugin("webpack-bundle-analyzer")
        .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
    }
    config.module
      .rule("images")
      .test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
      .use("image-webpack-loader")
      .loader("image-webpack-loader")
      .options({
        bypassOnDebug: true,
      })
      .end();
  },

结论: 使用了image-webpack-loader 后通过打不同的dist包 实现了图片从2M=>646kb的转变 压缩率很高

你可能感兴趣的:(前端)