UNPKG

@modern-js/builder

Version:
55 lines (54 loc) 2.09 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var networkPerformance_exports = {}; __export(networkPerformance_exports, { builderPluginNetworkPerformance: () => builderPluginNetworkPerformance }); module.exports = __toCommonJS(networkPerformance_exports); var import_builder_shared = require("@modern-js/builder-shared"); const builderPluginNetworkPerformance = () => ({ name: `builder-plugin-network-performance`, setup(api) { api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker, HtmlPlugin }) => { const config = api.getNormalizedConfig(); const { performance: { dnsPrefetch, preconnect } } = config; if (isServer || isWebWorker || isServiceWorker) { return; } if (dnsPrefetch) { chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(import_builder_shared.HtmlNetworkPerformancePlugin, [ dnsPrefetch, "dnsPrefetch", HtmlPlugin ]); } if (preconnect) { chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(import_builder_shared.HtmlNetworkPerformancePlugin, [ preconnect, "preconnect", HtmlPlugin ]); } }); } }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { builderPluginNetworkPerformance });