@modern-js/builder
Version:
Builder of modern.js.
58 lines (57 loc) • 2.15 kB
JavaScript
;
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 preloadOrPrefetch_exports = {};
__export(preloadOrPrefetch_exports, {
builderPluginPreloadOrPrefetch: () => builderPluginPreloadOrPrefetch
});
module.exports = __toCommonJS(preloadOrPrefetch_exports);
var import_builder_shared = require("@modern-js/builder-shared");
const builderPluginPreloadOrPrefetch = () => ({
name: `builder-plugin-preload-or-prefetch`,
setup(api) {
api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker, HtmlPlugin }) => {
const config = api.getNormalizedConfig();
const { performance: { preload, prefetch } } = config;
if (isServer || isWebWorker || isServiceWorker) {
return;
}
const HTMLCount = chain.entryPoints.values().length;
if (prefetch) {
chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(import_builder_shared.HTMLPreloadOrPrefetchPlugin, [
prefetch,
"prefetch",
HtmlPlugin,
HTMLCount
]);
}
if (preload) {
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(import_builder_shared.HTMLPreloadOrPrefetchPlugin, [
preload,
"preload",
HtmlPlugin,
HTMLCount
]);
}
});
}
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
builderPluginPreloadOrPrefetch
});