-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patheleventyWebcPlugin.js
71 lines (56 loc) · 2.51 KB
/
eleventyWebcPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const pkg = require("./package.json");
const templatePlugin = require("./src/eleventyWebcTemplate.js");
const transformPlugin = require("./src/eleventyWebcTransform.js");
module.exports = function(eleventyConfig, options = {}) {
eleventyConfig.versionCheck(pkg["11ty"].compatibility);
// Error for removed filters.
eleventyConfig.addFilter("webcGetCss", () => {
throw new Error("webcGetCss was removed from @11ty/eleventy-plugin-webc. Use the `getBundle('css')` shortcode instead.")
});
// Error for removed filters.
eleventyConfig.addFilter("webcGetJs", () => {
throw new Error("webcGetJs was removed from @11ty/eleventy-plugin-webc. Use the `getBundle('js')` shortcode instead.")
})
options = Object.assign({
components: "_components/**/*.webc", // glob for no-import global components
scopedHelpers: ["css", "js", "html"],
useTransform: false, // global transform
transformData: {}, // extra global data for transforms specifically
}, options);
options.bundlePluginOptions = Object.assign({
hoistDuplicateBundlesFor: ["css", "js"]
}, options.bundlePluginOptions);
if(options.components) {
let components = options.components;
if(!Array.isArray(components)) {
components = [components];
}
for(let entry of components) {
if(entry.startsWith("npm:")) {
continue;
}
eleventyConfig.addWatchTarget(entry);
// Opt-out of Eleventy to process components
// Note that Eleventy’s default ignores already have _includes/**
// This will cause component files outside of _includes to not be watched: https://github.com/11ty/eleventy-plugin-webc/issues/29
// Fixed in @11ty/[email protected]: https://github.com/11ty/eleventy/issues/893
eleventyConfig.ignores.add(entry);
}
}
// v0.12.0 upstream
// `bundlePluginOptions.toFileDirectory` (via Bundle Plugin changes) default changed from "bundle" to ""
// https://github.com/11ty/eleventy-plugin-bundle/releases/tag/v2.0.0
eleventyConfig.addBundle("html", Object.assign({}, options.bundlePluginOptions, {
hoist: options.bundlePluginOptions.hoistDuplicateBundlesFor.includes("html"),
}));
eleventyConfig.addBundle("css", Object.assign({}, options.bundlePluginOptions, {
hoist: options.bundlePluginOptions.hoistDuplicateBundlesFor.includes("css"),
}));
eleventyConfig.addBundle("js", Object.assign({}, options.bundlePluginOptions, {
hoist: options.bundlePluginOptions.hoistDuplicateBundlesFor.includes("js")
}));
templatePlugin(eleventyConfig, options);
if(options.useTransform) {
transformPlugin(eleventyConfig, options);
}
}