Skip to content

Commit

Permalink
Adds bundleExportKey feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed May 1, 2024
1 parent e2f2353 commit 528d425
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,25 @@ This does two things:
```js
module.exports = function(eleventyConfig) {
eleventyConfig.addBundle("css", {
// Optional, folder (relative to output directory) files will write to:
// (Optional) Folder (relative to output directory) files will write to
toFileDirectory: "bundle",

// Optional, defaults to bundle name
// (Optional) File extension used for bundle file output, defaults to bundle name
outputFileExtension: "css",

// Optional, defaults to bundle name
// (Optional) Name of shortcode for use in templates, defaults to bundle name
shortcodeName: "css",
// shortcodeName: false, // don’t add a shortcode.
// shortcodeName: false, // disable this feature.

// Optional, modify bundle content
// (Optional) Modify bundle content
transforms: [],

// Optional (advanced): if two identical code blocks exist in non-default buckets, they’ll be hoisted to the first bucket in common.
// (Optional) If two identical code blocks exist in non-default buckets, they’ll be hoisted to the first bucket in common.
hoist: true,

// (Optional) In 11ty.js templates, having a named export of `bundle` will populate your bundles.
bundleExportKey: "bundle",
// bundleExportKey: false, // disable this feature.
});
};
```
Expand Down
9 changes: 9 additions & 0 deletions codeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CodeManager {
this.isHoisting = true;
this.fileExtension = undefined;
this.toFileDirectory = undefined;
this.bundleExportKey = "bundle";
}

setFileExtension(ext) {
Expand All @@ -32,6 +33,14 @@ class CodeManager {
this.toFileDirectory = dir;
}

setBundleExportKey(key) {
this.bundleExportKey = key;
}

getBundleExportKey() {
return this.bundleExportKey;
}

reset() {
this.pages = {};
}
Expand Down
2 changes: 2 additions & 0 deletions eleventy.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function normalizeOptions(options = {}) {
// post-process
transforms: [],
hoistDuplicateBundlesFor: [],
bundleExportKey: "bundle", // use a `bundle` export in a 11ty.js template to populate bundles
}, options);

if(options.bundles !== false) {
Expand Down Expand Up @@ -42,6 +43,7 @@ function eleventyBundlePlugin(eleventyConfig, pluginOptions = {}) {
shortcodeName: name, // `false` will skip shortcode
transforms: pluginOptions.transforms,
toFileDirectory: pluginOptions.toFileDirectory,
bundleExportKey: pluginOptions.bundleExportKey, // `false` will skip bundle export
});
});
}
Expand Down
4 changes: 4 additions & 0 deletions eleventy.bundleManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module.exports = function(eleventyConfig, pluginOptions = {}) {
managers[name].setHoisting(bundleOptions.hoist);
}

if(bundleOptions.bundleExportKey !== undefined) {
managers[name].setBundleExportKey(bundleOptions.bundleExportKey);
}

if(bundleOptions.outputFileExtension) {
managers[name].setFileExtension(bundleOptions.outputFileExtension);
}
Expand Down

0 comments on commit 528d425

Please sign in to comment.