summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js')
-rw-r--r--node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js b/node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js
new file mode 100644
index 0000000..35f571c
--- /dev/null
+++ b/node_modules/@11ty/eleventy-plugin-bundle/eleventy.bundle.js
@@ -0,0 +1,72 @@
+import bundleManagersPlugin from "./src/eleventy.bundleManagers.js";
+import pruneEmptyBundlesPlugin from "./src/eleventy.pruneEmptyBundles.js";
+import globalShortcodesAndTransforms from "./src/eleventy.shortcodes.js";
+import debugUtil from "debug";
+
+const debug = debugUtil("Eleventy:Bundle");
+
+function normalizeOptions(options = {}) {
+ options = Object.assign({
+ // Plugin defaults
+
+ // Extra bundles
+ // css, js, and html are guaranteed unless `bundles: false`
+ bundles: [],
+ toFileDirectory: "bundle",
+ // post-process
+ transforms: [],
+ hoistDuplicateBundlesFor: [],
+ bundleExportKey: "bundle", // use a `bundle` export in a 11ty.js template to populate bundles
+
+ force: false, // force overwrite of existing getBundleManagers and addBundle configuration API methods
+ }, options);
+
+ if(options.bundles !== false) {
+ options.bundles = Array.from(new Set(["css", "js", "html", ...(options.bundles || [])]));
+ }
+
+ return options;
+}
+
+function eleventyBundlePlugin(eleventyConfig, pluginOptions = {}) {
+ eleventyConfig.versionCheck(">=3.0.0");
+ pluginOptions = normalizeOptions(pluginOptions);
+
+ let alreadyAdded = "getBundleManagers" in eleventyConfig || "addBundle" in eleventyConfig;
+ if(!alreadyAdded || pluginOptions.force) {
+ if(alreadyAdded && pluginOptions.force) {
+ debug("Bundle plugin already added via `addPlugin`, add was forced via `force: true`");
+ }
+
+ bundleManagersPlugin(eleventyConfig, pluginOptions);
+ }
+
+ // These can’t be unique (don’t skip re-add above), when the configuration file resets they need to be added again
+ pruneEmptyBundlesPlugin(eleventyConfig, pluginOptions);
+ globalShortcodesAndTransforms(eleventyConfig, pluginOptions);
+
+ // Support subsequent calls like addPlugin(BundlePlugin, { bundles: [] });
+ if(Array.isArray(pluginOptions.bundles)) {
+ debug("Adding bundles via `addPlugin`: %o", pluginOptions.bundles)
+ pluginOptions.bundles.forEach(name => {
+ let isHoisting = Array.isArray(pluginOptions.hoistDuplicateBundlesFor) && pluginOptions.hoistDuplicateBundlesFor.includes(name);
+
+ eleventyConfig.addBundle(name, {
+ hoist: isHoisting,
+ outputFileExtension: name, // default as `name`
+ shortcodeName: name, // `false` will skip shortcode
+ transforms: pluginOptions.transforms,
+ toFileDirectory: pluginOptions.toFileDirectory,
+ bundleExportKey: pluginOptions.bundleExportKey, // `false` will skip bundle export
+ });
+ });
+ }
+};
+
+// This is used to find the package name for this plugin (used in eleventy-plugin-webc to prevent dupes)
+Object.defineProperty(eleventyBundlePlugin, "eleventyPackage", {
+ value: "@11ty/eleventy-plugin-bundle"
+});
+
+export default eleventyBundlePlugin;
+export { normalizeOptions };