Skip to content

Latest commit

 

History

History
26 lines (25 loc) · 652 Bytes

课时-20.md

File metadata and controls

26 lines (25 loc) · 652 Bytes

课时 20:添加 prefetch + preload

module.exports = ({ config, resolve, options }) => {
  const PreloadWebpackPlugin = require("preload-webpack-plugin");
  return () => {
    config.plugin("preload").use(PreloadWebpackPlugin, [
      {
        rel: "preload",
        as(entry) {
          if (/\.css$/.test(entry)) return "style";
          if (/\.woff$/.test(entry)) return "font";
          if (/\.png$/.test(entry)) return "image";
          return "script";
        }
      }
    ]);
    config.plugin("prefetch").use(PreloadWebpackPlugin, [
      {
        rel: "prefetch",
        include: "asyncChunks"
      }
    ]);
  };
};