diff --git a/eleventy.bundle.js b/eleventy.bundle.js index 8a96bd1..ef0ee7b 100644 --- a/eleventy.bundle.js +++ b/eleventy.bundle.js @@ -34,10 +34,10 @@ function eleventyBundlePlugin(eleventyConfig, pluginOptions = {}) { if(Array.isArray(pluginOptions.bundles)) { debug("Adding bundles via `addPlugin`: %o", pluginOptions.bundles) pluginOptions.bundles.forEach(name => { - let hoist = Array.isArray(pluginOptions.hoistDuplicateBundlesFor) && pluginOptions.hoistDuplicateBundlesFor.includes(name); + let isHoisting = Array.isArray(pluginOptions.hoistDuplicateBundlesFor) && pluginOptions.hoistDuplicateBundlesFor.includes(name); eleventyConfig.addBundle(name, { - hoist, + hoist: isHoisting, outputFileExtension: name, // default as `name` shortcodeName: name, // `false` will skip shortcode transforms: pluginOptions.transforms, diff --git a/eleventy.bundleManagers.js b/eleventy.bundleManagers.js index fd74fb3..375ab28 100644 --- a/eleventy.bundleManagers.js +++ b/eleventy.bundleManagers.js @@ -41,9 +41,11 @@ module.exports = function(eleventyConfig, pluginOptions = {}) { // e.g. `css` shortcode to add code to page bundle // These shortcode names are not configurable on purpose (for wider plugin compatibility) - eleventyConfig.addPairedShortcode(shortcodeName, function addContent(content, bucket, urlOverride) { - let url = urlOverride || this.page.url; - managers[name].addToPage(url, content, bucket); + eleventyConfig.addPairedShortcode(shortcodeName, function addContent(content, bucket, explicitUrl) { + let url = explicitUrl || this.page?.url; + if(url) { // don’t add if a file doesn’t have an output URL + managers[name].addToPage(url, content, bucket); + } return ""; }); } diff --git a/eleventy.shortcodes.js b/eleventy.shortcodes.js index 9f055a0..8f7ee1c 100644 --- a/eleventy.shortcodes.js +++ b/eleventy.shortcodes.js @@ -22,13 +22,14 @@ module.exports = function(eleventyConfig, pluginOptions = {}) { // e.g. `getBundle` shortcode to get code in current page bundle // bucket can be an array // This shortcode name is not configurable on purpose (for wider plugin compatibility) - eleventyConfig.addShortcode("getBundle", function getContent(type, bucket) { + eleventyConfig.addShortcode("getBundle", function getContent(type, bucket, explicitUrl) { if(!type || !(type in managers) || Object.keys(managers).length === 0) { throw new Error(`Invalid bundle type: ${type}. Available options: ${Object.keys(managers)}`); } - if(this.page.url) { - pagesUsingBundles[this.page.url] = true; + let url = explicitUrl || this.page?.url; + if(url) { + pagesUsingBundles[url] = true; } return OutOfOrderRender.getAssetKey("get", type, bucket); @@ -36,13 +37,14 @@ module.exports = function(eleventyConfig, pluginOptions = {}) { // write a bundle to the file system // This shortcode name is not configurable on purpose (for wider plugin compatibility) - eleventyConfig.addShortcode("getBundleFileUrl", function(type, bucket) { + eleventyConfig.addShortcode("getBundleFileUrl", function(type, bucket, explicitUrl) { if(!type || !(type in managers) || Object.keys(managers).length === 0) { throw new Error(`Invalid bundle type: ${type}. Available options: ${Object.keys(managers)}`); } - if(this.page.url) { - pagesUsingBundles[this.page.url] = true; + let url = explicitUrl || this.page?.url; + if(url) { + pagesUsingBundles[url] = true; } return OutOfOrderRender.getAssetKey("file", type, bucket);