diff --git a/BundleFileOutput.js b/BundleFileOutput.js index 5e3804a..b9b376e 100644 --- a/BundleFileOutput.js +++ b/BundleFileOutput.js @@ -11,7 +11,7 @@ const debug = require("debug")("Eleventy:Bundle"); class BundleFileOutput { constructor(outputDirectory, bundleDirectory) { this.outputDirectory = outputDirectory; - this.bundleDirectory = bundleDirectory; + this.bundleDirectory = bundleDirectory || ""; this.hashLength = 10; this.fileExtension = undefined; } diff --git a/codeManager.js b/codeManager.js index d9c381f..c5a27c3 100644 --- a/codeManager.js +++ b/codeManager.js @@ -17,6 +17,7 @@ class CodeManager { this.transforms = []; this.isHoisting = true; this.fileExtension = undefined; + this.toFileDirectory = undefined; } setFileExtension(ext) { @@ -27,6 +28,10 @@ class CodeManager { this.isHoisting = !!enabled; } + setBundleDirectory(dir) { + this.toFileDirectory = dir; + } + reset() { this.pages = {}; } @@ -145,13 +150,13 @@ class CodeManager { return ""; } - let { output, bundle, write } = options; + let { output, write } = options; buckets = CodeManager.normalizeBuckets(buckets); // TODO the bundle output URL might be useful in the transforms for sourcemaps let content = await this.getForPage(pageData, buckets); - let writer = new BundleFileOutput(output, bundle); + let writer = new BundleFileOutput(output, this.toFileDirectory); writer.setFileExtension(this.fileExtension); return writer.writeBundle(content, this.name, write); } diff --git a/eleventy.bundle.js b/eleventy.bundle.js index 80eef35..8a96bd1 100644 --- a/eleventy.bundle.js +++ b/eleventy.bundle.js @@ -41,6 +41,7 @@ function eleventyBundlePlugin(eleventyConfig, pluginOptions = {}) { outputFileExtension: name, // default as `name` shortcodeName: name, // `false` will skip shortcode transforms: pluginOptions.transforms, + toFileDirectory: pluginOptions.toFileDirectory, }); }); } diff --git a/eleventy.bundleManagers.js b/eleventy.bundleManagers.js index 92c3631..fd74fb3 100644 --- a/eleventy.bundleManagers.js +++ b/eleventy.bundleManagers.js @@ -26,6 +26,10 @@ module.exports = function(eleventyConfig, pluginOptions = {}) { managers[name].setFileExtension(bundleOptions.outputFileExtension); } + if(bundleOptions.toFileDirectory) { + managers[name].setBundleDirectory(bundleOptions.toFileDirectory); + } + if(bundleOptions.transforms) { managers[name].setTransforms(bundleOptions.transforms); } diff --git a/eleventy.shortcodes.js b/eleventy.shortcodes.js index 426ebaf..9f055a0 100644 --- a/eleventy.shortcodes.js +++ b/eleventy.shortcodes.js @@ -69,8 +69,7 @@ module.exports = function(eleventyConfig, pluginOptions = {}) { render.setAssetManager(key, managers[key]); } - render.setOutputDirectory(eleventyConfig.dir.output); - render.setBundleDirectory(pluginOptions.toFileDirectory); + render.setOutputDirectory(eleventyConfig.directories.output); render.setWriteToFileSystem(writeToFileSystem); return render.replaceAll(this.page); diff --git a/outOfOrderRender.js b/outOfOrderRender.js index f3cce38..282c958 100644 --- a/outOfOrderRender.js +++ b/outOfOrderRender.js @@ -31,10 +31,6 @@ class OutOfOrderRender { this.outputDirectory = dir; } - setBundleDirectory(dir) { - this.bundleDirectory = dir; - } - normalizeMatch(match) { if(match.startsWith("/*__EleventyBundle:")) { let [prefix, type, name, bucket, suffix] = match.split(OutOfOrderRender.SEPARATOR); @@ -130,7 +126,6 @@ class OutOfOrderRender { // returns promise return manager.writeBundle(pageData, bucket, { output: this.outputDirectory, - bundle: this.bundleDirectory, write: this.writeToFileSystem, }); } diff --git a/sample/sample-config.js b/sample/sample-config.js index 95048fc..b52d1b0 100644 --- a/sample/sample-config.js +++ b/sample/sample-config.js @@ -8,16 +8,20 @@ module.exports = function(eleventyConfig) { }); // adds html, css, js (maintain existing API) - eleventyConfig.addPlugin(bundlePlugin); + eleventyConfig.addPlugin(bundlePlugin, { + toFileDirectory: "bundle1" + }); - // ignored, already exists - eleventyConfig.addBundle("css"); - // ignored, already exists - eleventyConfig.addBundle("css"); - // ignored, already exists - eleventyConfig.addBundle("css"); - // ignored, already exists - eleventyConfig.addBundle("html"); + eleventyConfig.addPlugin(eleventyConfig => { + // ignored, already exists + eleventyConfig.addBundle("css"); + // ignored, already exists + eleventyConfig.addBundle("css"); + // ignored, already exists + eleventyConfig.addBundle("css"); + // ignored, already exists + eleventyConfig.addBundle("html"); + }); // new! eleventyConfig.addBundle("stylesheet", { diff --git a/sample/test.njk b/sample/test.njk index 74a7636..c8ea142 100644 --- a/sample/test.njk +++ b/sample/test.njk @@ -23,4 +23,5 @@ And now you can use `icon-close` in as many SVG instances as you’d like (witho - \ No newline at end of file + +{# #} \ No newline at end of file