@11ty/eleventy-plugin-webc 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ on: push
2
+ jobs:
3
+ build:
4
+ runs-on: ${{ matrix.os }}
5
+ strategy:
6
+ matrix:
7
+ os: ["ubuntu-latest", "macos-latest", "windows-latest"]
8
+ node: ["14", "16", "18"]
9
+ name: Node.js ${{ matrix.node }} on ${{ matrix.os }}
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+ - name: Setup node
13
+ uses: actions/setup-node@v3
14
+ with:
15
+ node-version: ${{ matrix.node }}
16
+ # cache: npm
17
+ - run: npm install
18
+ - run: npm test
19
+ env:
20
+ YARN_GPG: no
package/README.md ADDED
@@ -0,0 +1,264 @@
1
+ <p align="center"><img src="https://www.11ty.dev/img/logo-github.svg" width="200" height="200" alt="11ty Logo"></p>
2
+
3
+ # eleventy-plugin-webc 🕚⚡️🎈🐀
4
+
5
+ Adds support for [WebC, the single file web component format](https://github.com/11ty/webc), to Eleventy.
6
+
7
+ ## Features
8
+
9
+ * All of the [framework-independent WebC features](https://github.com/11ty/webc#features) out of the box.
10
+ * First-class incremental support (for page templates, components, and Eleventy layouts): use with `--incremental`
11
+ * Tired of importing components?
12
+ * Configure no-import global web components
13
+ * Configure no-import components in the data cascade to apply to a single template, a directory of templates, or a complex hierarchy of folders-o-templates.
14
+ * Easiliy roll up the CSS and JS in-use by WebC components on a page for page-specific bundles. Dirt-simple critical CSS/JS to only load the code you need.
15
+ * Components can roll up CSS/JS assets to arbitrary buckets for custom use!
16
+ * For more complex templating needs, you _can_ render any existing Eleventy template syntax inside of WebC.
17
+ * Works great with out of the box with [is-land](https://www.11ty.dev/docs/plugins/partial-hydration/)
18
+
19
+ ## ➡ [Documentation](https://www.11ty.dev/docs/languages/webc/)
20
+
21
+ - Please star [Eleventy on GitHub](https://github.com/11ty/eleventy/)!
22
+ - Follow us on Twitter [@eleven_ty](https://twitter.com/eleven_ty)
23
+ - Support [11ty on Open Collective](https://opencollective.com/11ty)
24
+ - Subscribe to our [YouTube channel](https://11ty.dev/youtube)
25
+ - [11ty on npm](https://www.npmjs.com/org/11ty)
26
+ - [11ty on GitHub](https://github.com/11ty)
27
+
28
+ [![npm Version](https://img.shields.io/npm/v/@11ty/eleventy-plugin-webc.svg?style=for-the-badge)](https://www.npmjs.com/package/@11ty/eleventy-plugin-webc)
29
+
30
+ ## Installation
31
+
32
+ You’ve found this early! It’s not yet on npm.
33
+
34
+ <!--
35
+ ```
36
+ npm install @11ty/eleventy-plugin-webc
37
+ ```
38
+ -->
39
+
40
+ ## Usage
41
+
42
+ Enable the plugin in your Eleventy configuration file:
43
+
44
+ ```js
45
+ const pluginWebc = require("@11ty/eleventy-plugin-webc");
46
+
47
+ module.exports = function(eleventyConfig) {
48
+ eleventyConfig.addPlugin(pluginWebc);
49
+ };
50
+ ```
51
+
52
+ ### Full options list
53
+
54
+ ```js
55
+ const pluginWebc = require("@11ty/eleventy-plugin-webc");
56
+
57
+ module.exports = function(eleventyConfig) {
58
+ eleventyConfig.addPlugin(pluginWebc, {
59
+ // Glob to find no-import global components
60
+ components: "_includes/components/**/*.webc", // defaults to `false`
61
+ });
62
+ };
63
+ ```
64
+
65
+ ## Examples
66
+
67
+ Add a new `.webc` file to your Eleventy input directory and it will render as WebC to your output directory (`_site` by default).
68
+
69
+ `my-page.webc`:
70
+
71
+ ```html
72
+ <!doctype html>
73
+ <html lang="en">
74
+ <head>
75
+ <meta charset="utf-8">
76
+ <title>WebC Example</title>
77
+ </head>
78
+ <body>
79
+ WebC *is* HTML.
80
+ </body>
81
+ </html>
82
+ ```
83
+
84
+ ### Use Front Matter
85
+
86
+ WebC in Eleventy works automatically with standard Eleventy conventions for [front matter](https://www.11ty.dev/docs/data-frontmatter/) (though front matter in Eleventy is _optional_).
87
+
88
+ Notably you can use `yaml`, `json`, `js`, or [add your own data format](https://www.11ty.dev/docs/data-frontmatter-customize/) for front matter in Eleventy.
89
+
90
+ `with-front-matter.webc` (using `_includes/my-layout.webc` as an [Eleventy layout](https://www.11ty.dev/docs/layouts/)):
91
+
92
+ ```html
93
+ ---
94
+ layout: "my-layout.webc"
95
+ ---
96
+ <my-webc-component>WebC *is* HTML.</my-webc-component>
97
+ ```
98
+
99
+ `_includes/my-layout.webc`:
100
+
101
+ ```html
102
+ <!doctype html>
103
+ <html lang="en">
104
+ <head>
105
+ <meta charset="utf-8">
106
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
107
+ <meta name="description" content="">
108
+ <title></title>
109
+ </head>
110
+ <body @html="this.content"></body>
111
+ </html>
112
+ ```
113
+
114
+ ### Components
115
+
116
+ There are a few ways to use web components here:
117
+
118
+ 1. You can use `webc:import` inside of your components to import another component directly.
119
+ 2. Use global no-import components specified in your config file
120
+ 3. Specify a glob of no-import components at a directory or template level in the data cascade
121
+
122
+ Notably, WebC components are not restricted to the same naming limitations as custom elements (they do not require a dash in the name). The [WebC documentation has all of the detail on how to use and configure WebC components](https://github.com/11ty/webc#html-imports-kidding-kinda).
123
+
124
+ #### Global no-import Components
125
+
126
+ Use the `components` property in the Full options list in your Eleventy configuration file to specify project-wide WebC component files available for use in any page.
127
+
128
+ #### Specify no-import Components in the Data Cascade
129
+
130
+ You can also use and configure specific components as part of the data cascade as well (global to a folder or a specific template) by assigning a glob (or array of globs) to `webc.components`, like so:
131
+
132
+ `my-directory/my-page.webc`:
133
+
134
+ ```html
135
+ ---
136
+ layout: "my-layout.webc"
137
+ webc:
138
+ components: "./webc/*.webc"
139
+ ---
140
+ <my-webc-component>WebC *is* HTML.</my-webc-component>
141
+ ```
142
+
143
+ * Usage warning: By default these paths are relative to the template file. If you’re setting this in the data cascade to apply multiple child folders deep, it might be better to use the global no-import components option above OR to use `~/` as a prefix (e.g. `~/my-directory/webc/*.webc`) to alias to the project’s root directory.
144
+
145
+ ### CSS and JS
146
+
147
+ [Eleventy Layouts](https://www.11ty.dev/docs/layouts/) can bundle any specific page’s assets (CSS and JS used by components on the page). These are automatically rolled up when a component uses `<script>` or `<style>`. You can use this to easily implement component-driven Critical CSS.
148
+
149
+ `_includes/webc/my-webc-component.webc`:
150
+
151
+ ```html
152
+ <style>/* This is component CSS */</style>
153
+ <script>/* This is component JS */</script>
154
+ ```
155
+
156
+ `_includes/layout.webc`:
157
+
158
+ ```html
159
+ <!doctype html>
160
+ <html lang="en">
161
+ <head>
162
+ <meta charset="utf-8">
163
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
164
+ <meta name="description" content="">
165
+ <title></title>
166
+ <style @html="this.getCSS(this.page.url)"></style>
167
+ <script @html="this.getJS(this.page.url)"></script>
168
+ </head>
169
+ <body @html="this.content"></body>
170
+ </html>
171
+ ```
172
+
173
+ #### Asset bucketing
174
+
175
+ Components can use the `webc:bucket` feature to output to any arbitrary bucket name for compartmentalization at the component level.
176
+
177
+ `_includes/webc/my-webc-component.webc`:
178
+
179
+ ```html
180
+ <style>/* This CSS is put into the default bucket */</style>
181
+ <script>/* This JS is put into the default bucket */</script>
182
+ <style webc:bucket="defer">/* This CSS is put into the `defer` bucket */</style>
183
+ <script webc:bucket="defer">/* This JS is put into the `defer` bucket */</script>
184
+ ```
185
+
186
+ ```html
187
+ <!doctype html>
188
+ <html lang="en">
189
+ <head>
190
+ <meta charset="utf-8">
191
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
192
+ <meta name="description" content="">
193
+ <title></title>
194
+ <!-- Default bucket -->
195
+ <style @html="this.getCSS(this.page.url)"></style>
196
+ <script @html="this.getJS(this.page.url)"></script>
197
+ </head>
198
+ <body>
199
+ <template webc:nokeep @html="this.content"></template>
200
+
201
+ <!-- `defer` bucket -->
202
+ <style @html="this.getCSS(this.page.url, 'defer')"></style>
203
+ <script @html="this.getJS(this.page.url, 'defer')"></script>
204
+ </body>
205
+ </html>
206
+ ```
207
+
208
+ ### Use any Eleventy Template Syntax
209
+
210
+ We’ve wired up [WebC’s Custom Transforms feature](https://github.com/11ty/webc#custom-transforms) `webc:type="11ty"` to the [Eleventy Render plugin](https://www.11ty.dev/docs/plugins/render/) to allow you to use existing Eleventy template syntax inside of WebC.
211
+
212
+ Use the `11ty:type` attribute to specify a [valid template syntax](https://www.11ty.dev/docs/plugins/render/#rendertemplate).
213
+
214
+ `my-page.webc`:
215
+
216
+ ```
217
+ ---
218
+ frontmatterdata: "Hello from Front Matter"
219
+ ---
220
+ <template webc:type="11ty" 11ty:type="liquid,md">
221
+ {% assign t = "Liquid in WebC" %}
222
+ ## {{ t }}
223
+
224
+ _{{ frontmatterdata }}_
225
+ </template>
226
+ ```
227
+
228
+ You have full access to the data cascade here (see `frontmatterdata` in the example above).
229
+
230
+ ### Use with `is-land`
231
+
232
+ You can also use this out of the box with Eleventy’s [`is-land` component for web component hydration](https://www.11ty.dev/docs/plugins/partial-hydration/).
233
+
234
+ At the component level, components can declare their own is-land loading conditions.
235
+
236
+ _(Some features here require `is-land` 1.0.1 or newer)_
237
+
238
+ `_includes/webc/my-webc-component.webc`:
239
+
240
+ ```html
241
+ <is-land on:visible>
242
+ <style media="module/island" webc:keep>
243
+ /* This is some is-land on-visible CSS */
244
+ </style>
245
+ <script type="module/island" webc:keep>
246
+ console.log("This is some is-land on-visible JavaScript");
247
+ </script>
248
+
249
+ <link rel="stylesheet" media="style/island" href="some-arbitrary-css.css">
250
+ <script type="module/island" src="some-arbitrary-js.js"></script>
251
+ </is-land>
252
+
253
+ <is-land on:interaction>
254
+ <style media="module/island" webc:keep>
255
+ /* This is some is-land on-interaction CSS */
256
+ </style>
257
+ <script type="module/island" webc:keep>
258
+ console.log("This is some is-land on-interaction JavaScript");
259
+ </script>
260
+
261
+ <link rel="stylesheet" media="style/island" href="some-arbitrary-css.css">
262
+ <script type="module/island" src="some-arbitrary-js.js"></script>
263
+ </is-land>
264
+ ```
@@ -0,0 +1,155 @@
1
+ const pkg = require("./package.json");
2
+ const path = require("path");
3
+ const { EleventyRenderPlugin } = require("@11ty/eleventy");
4
+ const EleventyRenderManager = EleventyRenderPlugin.RenderManager;
5
+
6
+ const CodeManager = require("./src/codeManager.js");
7
+ const WebCIncremental = require("./src/incremental.js");
8
+
9
+ function relativePath(inputPath, newGlob) {
10
+ // project root
11
+ if(newGlob.startsWith("~/")) {
12
+ let rootRelativePath = "." + newGlob.slice(1);
13
+ return rootRelativePath;
14
+ }
15
+
16
+ let { dir } = path.parse(inputPath);
17
+ // globs must have forward slashes (even on Windows)
18
+ let templateRelativePath = path.join(dir, newGlob).split(path.sep).join("/");
19
+ return templateRelativePath;
20
+ }
21
+
22
+ /* TODO
23
+ * Use JavaScript functions or universal shortcodes as built-in components?
24
+ */
25
+
26
+ module.exports = function(eleventyConfig, options = {}) {
27
+ try {
28
+ eleventyConfig.versionCheck(pkg["11ty"].compatibility);
29
+ } catch(e) {
30
+ console.log( `WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}` );
31
+ }
32
+
33
+ options = Object.assign({
34
+ components: false, // glob for no-import global components
35
+ }, options);
36
+
37
+ if(options.components) {
38
+ eleventyConfig.addWatchTarget(options.components);
39
+ }
40
+
41
+ eleventyConfig.addTemplateFormats("webc");
42
+
43
+ let renderManager = new EleventyRenderManager();
44
+ let cssManager = new CodeManager();
45
+ let jsManager = new CodeManager();
46
+
47
+ eleventyConfig.on("eleventy.before", () => {
48
+ cssManager.reset();
49
+ jsManager.reset();
50
+ });
51
+
52
+ function getCss(pageUrl, bucket = "default") {
53
+ return cssManager.getForPage(pageUrl, bucket);
54
+ }
55
+
56
+ function getJs(pageUrl, bucket = "default") {
57
+ return jsManager.getForPage(pageUrl, bucket);
58
+ }
59
+
60
+ // TODO
61
+ // eleventyConfig.addFilter("webcGetCSS", (url, bucket) => getCss(url, bucket));
62
+ // eleventyConfig.addFilter("webcGetJS", (url, bucket) => getJs(url, bucket));
63
+
64
+ let incremental = new WebCIncremental();
65
+
66
+ eleventyConfig.on("eleventy.layouts", layouts => {
67
+ incremental.setLayouts(layouts);
68
+ });
69
+
70
+ eleventyConfig.on("eleventy.before", () => {
71
+ incremental.setComponents(options.components);
72
+ });
73
+
74
+ eleventyConfig.addExtension("webc", {
75
+ outputFileExtension: "html",
76
+
77
+ init: async function() {
78
+ // For ESM in CJS
79
+ let e = await import("@11ty/webc");
80
+ incremental.setWebC(e.WebC);
81
+
82
+ if(incremental.needsComponents()) {
83
+ incremental.setComponents(options.components);
84
+ }
85
+ },
86
+
87
+ isIncrementalMatch: function (incrementalFilePath) {
88
+ // Eleventy layouts don’t appear directly in the WebC component graph, so we use the `eleventy.layouts` map here
89
+ if(incremental.isTemplateUsingLayout(this.inputPath, incrementalFilePath)) {
90
+ return true;
91
+ }
92
+
93
+ let {page, setup} = incremental.get(this.inputPath);
94
+ if(page && setup) {
95
+ if(page.getComponents(setup).includes(incrementalFilePath)) {
96
+ return true;
97
+ }
98
+ }
99
+
100
+ return false;
101
+ },
102
+
103
+ compile: async function(inputContent, inputPath) {
104
+ let page = incremental.add(inputContent, inputPath);
105
+
106
+ page.setHelper("getCSS", function(url, bucket) {
107
+ return getCss(url, bucket);
108
+ });
109
+
110
+ page.setHelper("getJS", function(url, bucket) {
111
+ return getJs(url, bucket);
112
+ });
113
+
114
+ page.setTransform("11ty", async function(content) {
115
+ let syntax = this["11ty:type"];
116
+ if(syntax) {
117
+ let fn = await renderManager.compile(content, syntax);
118
+ return renderManager.render(fn, this, {});
119
+ }
120
+ return content;
121
+ });
122
+
123
+ return async (data) => {
124
+ let setupObject = { data };
125
+ if(data.webc?.components) {
126
+ setupObject.components = incremental.getComponentMap(relativePath(data.page.inputPath, data.webc.components));
127
+ }
128
+
129
+ let setup = await page.setup(setupObject);
130
+ incremental.addSetup(inputPath, setup);
131
+
132
+ let { ast, serializer } = setup;
133
+ let { html, css, js, buckets } = await serializer.compile(ast);
134
+
135
+ cssManager.addToPage(data.page.url, css, "default");
136
+
137
+ if(buckets.css) {
138
+ for(let bucket in buckets.css) {
139
+ cssManager.addToPage(data.page.url, buckets.css[bucket], bucket);
140
+ }
141
+ }
142
+
143
+ jsManager.addToPage(data.page.url, js, "default");
144
+
145
+ if(buckets.js) {
146
+ for(let bucket in buckets.js) {
147
+ jsManager.addToPage(data.page.url, buckets.js[bucket], bucket);
148
+ }
149
+ }
150
+
151
+ return html;
152
+ };
153
+ }
154
+ });
155
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@11ty/eleventy-plugin-webc",
3
+ "version": "0.3.1",
4
+ "description": "WebC support for Eleventy adds for Single File Web Components",
5
+ "main": "eleventyWebcPlugin.js",
6
+ "scripts": {
7
+ "test": "npx ava"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "license": "MIT",
13
+ "engines": {
14
+ "node": ">=14.18"
15
+ },
16
+ "11ty": {
17
+ "compatibility": ">=2.0.0-canary.16"
18
+ },
19
+ "funding": {
20
+ "type": "opencollective",
21
+ "url": "https://opencollective.com/11ty"
22
+ },
23
+ "keywords": [
24
+ "eleventy",
25
+ "eleventy-plugin",
26
+ "web-components",
27
+ "custom-elements"
28
+ ],
29
+ "author": {
30
+ "name": "Zach Leatherman",
31
+ "email": "zachleatherman@gmail.com",
32
+ "url": "https://zachleat.com/"
33
+ },
34
+ "ava": {
35
+ "failFast": true,
36
+ "files": [
37
+ "./test/*.js"
38
+ ]
39
+ },
40
+ "dependencies": {
41
+ "@11ty/eleventy": "^2.0.0-canary.16",
42
+ "@11ty/webc": "^0.3.1"
43
+ },
44
+ "devDependencies": {
45
+ "ava": "^4.3.3"
46
+ }
47
+ }
@@ -0,0 +1,33 @@
1
+ class Manager {
2
+ constructor() {
3
+ this.reset();
4
+ }
5
+
6
+ reset() {
7
+ this.pages = {};
8
+ }
9
+
10
+ addToPage(pageUrl, code = [], bucket = "default") {
11
+ if(code.length === 0) {
12
+ return;
13
+ }
14
+
15
+ if(!this.pages[pageUrl]) {
16
+ this.pages[pageUrl] = {};
17
+ }
18
+ if(!this.pages[pageUrl][bucket]) {
19
+ this.pages[pageUrl][bucket] = new Set();
20
+ }
21
+
22
+ this.pages[pageUrl][bucket].add(code.join("\n"));
23
+ }
24
+
25
+ getForPage(pageUrl, bucket = "default") {
26
+ if(this.pages[pageUrl]) {
27
+ return Array.from(this.pages[pageUrl][bucket] || []).join("\n");
28
+ }
29
+ return "";
30
+ }
31
+ }
32
+
33
+ module.exports = Manager;
@@ -0,0 +1,81 @@
1
+ class WebCIncremental {
2
+ constructor() {
3
+ this.pages = {};
4
+ this.setups = {};
5
+ this.globalComponentsMap = false;
6
+ this.components = {};
7
+ }
8
+
9
+ setWebC(cls) {
10
+ this.webc = cls;
11
+ }
12
+
13
+ needsComponents() {
14
+ return this.globalComponentsMap === false;
15
+ }
16
+
17
+ setComponents(glob) {
18
+ let map = this.getComponentMap(glob);
19
+ if(map) {
20
+ this.globalComponentsMap = map;
21
+ }
22
+ }
23
+
24
+ getComponentMap(glob) {
25
+ if(!this.webc) {
26
+ return false;
27
+ }
28
+
29
+ let WebC = this.webc;
30
+ let components = WebC.getComponentsMap(glob);
31
+ // console.log( glob, Object.keys(components).length );
32
+ return components;
33
+ }
34
+
35
+ setLayouts(layouts) {
36
+ this.layouts = layouts;
37
+ }
38
+
39
+ isTemplateUsingLayout(templateFilePath, layoutFilePath) {
40
+ if(this.layouts && this.layouts[layoutFilePath] && this.layouts[layoutFilePath].includes(templateFilePath)) {
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+
46
+ add(inputContent, inputPath) {
47
+ let WebC = this.webc;
48
+ let page = new WebC();
49
+ page.setContent(inputContent, inputPath);
50
+
51
+ if(this.globalComponentsMap) {
52
+ page.defineComponents(this.globalComponentsMap);
53
+ }
54
+
55
+ this.pages[inputPath] = page;
56
+
57
+ return page;
58
+ }
59
+
60
+ addSetup(inputPath, setup) {
61
+ this.setups[inputPath] = setup;
62
+ this.components[inputPath] = setup.serializer.components;
63
+ }
64
+
65
+ get(inputPath) {
66
+ let setup = this.setups[inputPath];
67
+ let components = this.components[inputPath];
68
+
69
+ if(setup && components) {
70
+ setup.serializer.restorePreparsedComponents(components);
71
+ }
72
+
73
+ return {
74
+ page: this.pages[inputPath],
75
+ setup,
76
+ components,
77
+ }
78
+ }
79
+ }
80
+
81
+ module.exports = WebCIncremental;
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta name="description" content="">
7
+ <title></title>
8
+ <style @html="this.getCSS(this.page.url)"></style>
9
+ <script @html="this.getJS(this.page.url)"></script>
10
+ </head>
11
+ <body>
12
+ <template webc:nokeep @html="this.content"></template>
13
+
14
+ <style @html="this.getCSS(this.page.url, 'defer')"></style>
15
+ <script @html="this.getJS(this.page.url, 'defer')"></script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,12 @@
1
+ const EleventyWebcPlugin = require("../../eleventyWebcPlugin.js");
2
+
3
+ module.exports = function (eleventyConfig) {
4
+ eleventyConfig.addPlugin(EleventyWebcPlugin);
5
+
6
+ return {
7
+ dir: {
8
+ includes: "_includes",
9
+ layouts: "_layouts",
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ ---
2
+ frontmatterdata: "HELLO FROM FRONT MATTER"
3
+ layout: layout.webc
4
+ ---
5
+ <say-hello></say-hello>
6
+ <say-hello></say-hello>
7
+ WHO IS THIS
8
+ hi
9
+ <span @html="this.frontmatterdata"></span>
@@ -0,0 +1 @@
1
+ This is a component.
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta name="description" content="">
7
+ <title></title>
8
+ <style @html="this.getCSS(this.page.url)"></style>
9
+ <script @html="this.getJS(this.page.url)"></script>
10
+ </head>
11
+ <body>
12
+ <template webc:nokeep @html="this.content"></template>
13
+
14
+ <style @html="this.getCSS(this.page.url, 'defer')"></style>
15
+ <script @html="this.getJS(this.page.url, 'defer')"></script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,15 @@
1
+ const EleventyWebcPlugin = require("../../eleventyWebcPlugin.js");
2
+
3
+ module.exports = function (eleventyConfig) {
4
+ eleventyConfig.addPlugin(EleventyWebcPlugin, {
5
+ components: "test/sample-2/_includes/**/*.webc"
6
+ });
7
+ // eleventyConfig.addPlugin(EleventyWebcPlugin);
8
+
9
+ return {
10
+ dir: {
11
+ includes: "_includes",
12
+ layouts: "_layouts",
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,9 @@
1
+ ---
2
+ frontmatterdata: "HELLO FROM FRONT MATTER"
3
+ layout: layout.webc
4
+ ---
5
+ <component></component>
6
+ <component></component>
7
+ WHO IS THIS
8
+ hi
9
+ <span @html="this.frontmatterdata"></span>
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta name="description" content="">
7
+ <title></title>
8
+ <style @html="this.getCSS(this.page.url)"></style>
9
+ <script @html="this.getJS(this.page.url)"></script>
10
+ </head>
11
+ <body>
12
+ <template webc:nokeep @html="this.content"></template>
13
+
14
+ <style @html="this.getCSS(this.page.url, 'defer')"></style>
15
+ <script @html="this.getJS(this.page.url, 'defer')"></script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,12 @@
1
+ const EleventyWebcPlugin = require("../../eleventyWebcPlugin.js");
2
+
3
+ module.exports = function (eleventyConfig) {
4
+ eleventyConfig.addPlugin(EleventyWebcPlugin);
5
+
6
+ return {
7
+ dir: {
8
+ includes: "_includes",
9
+ layouts: "_layouts",
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ ---
2
+ frontmatterdata: "HELLO FROM FRONT MATTER"
3
+ layout: layout.webc
4
+ webc:
5
+ components: "~/test/sample-page-global-components/_includes/page1-components/*.webc"
6
+ ---
7
+ <say-hello></say-hello>
8
+ <say-hello></say-hello>
9
+ WHO IS THIS
10
+ hi
11
+ <span @html="this.frontmatterdata"></span>
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta name="description" content="">
7
+ <title></title>
8
+ <style @html="this.getCSS(this.page.url)"></style>
9
+ <script @html="this.getJS(this.page.url)"></script>
10
+ </head>
11
+ <body>
12
+ <template webc:nokeep @html="this.content"></template>
13
+
14
+ <style @html="this.getCSS(this.page.url, 'defer')"></style>
15
+ <script @html="this.getJS(this.page.url, 'defer')"></script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,12 @@
1
+ const EleventyWebcPlugin = require("../../eleventyWebcPlugin.js");
2
+
3
+ module.exports = function (eleventyConfig) {
4
+ eleventyConfig.addPlugin(EleventyWebcPlugin);
5
+
6
+ return {
7
+ dir: {
8
+ includes: "_includes",
9
+ layouts: "_layouts",
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ ---
2
+ frontmatterdata: "HELLO FROM FRONT MATTER"
3
+ layout: layout.webc
4
+ webc:
5
+ components: "./_includes/page1-components/*.webc"
6
+ ---
7
+ <say-hello></say-hello>
8
+ <say-hello></say-hello>
9
+ WHO IS THIS
10
+ hi
11
+ <span @html="this.frontmatterdata"></span>
package/test/test.js ADDED
@@ -0,0 +1,131 @@
1
+ const test = require("ava");
2
+ const Eleventy = require("@11ty/eleventy");
3
+
4
+ test("Sample page", async t => {
5
+ let elev = new Eleventy("./test/sample-1/page.webc", "./test/sample-1/_site", {
6
+ configPath: "./test/sample-1/eleventy.config.js"
7
+ });
8
+
9
+ let results = await elev.toJSON();
10
+ let [result] = results;
11
+
12
+ t.is(result.content.trim(), `<!doctype html>
13
+ <html lang="en">
14
+ <head>
15
+ <meta charset="utf-8">
16
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
17
+ <meta name="description" content>
18
+ <title></title>
19
+ <style></style>
20
+ <script></script>
21
+ </head>
22
+ <body>
23
+ <say-hello></say-hello>
24
+ <say-hello></say-hello>
25
+ WHO IS THIS
26
+ hi
27
+ <span>HELLO FROM FRONT MATTER</span>
28
+
29
+ <style></style>
30
+ <script></script>
31
+
32
+ </body>
33
+ </html>`);
34
+ });
35
+
36
+ test("Sample page with global component", async t => {
37
+ let elev = new Eleventy("./test/sample-2/page.webc", "./test/sample-2/_site", {
38
+ configPath: "./test/sample-2/eleventy.config.js"
39
+ });
40
+
41
+ let results = await elev.toJSON();
42
+ let [result] = results;
43
+
44
+ t.is(result.content.trim(), `<!doctype html>
45
+ <html lang="en">
46
+ <head>
47
+ <meta charset="utf-8">
48
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
49
+ <meta name="description" content>
50
+ <title></title>
51
+ <style></style>
52
+ <script></script>
53
+ </head>
54
+ <body>
55
+ This is a component.
56
+ This is a component.
57
+ WHO IS THIS
58
+ hi
59
+ <span>HELLO FROM FRONT MATTER</span>
60
+
61
+ <style></style>
62
+ <script></script>
63
+
64
+ </body>
65
+ </html>`);
66
+ });
67
+
68
+ test("Page with front matter no-import components", async t => {
69
+ let elev = new Eleventy("./test/sample-page-global-components/page.webc", "./test/sample-page-global-components/_site", {
70
+ configPath: "./test/sample-page-global-components/eleventy.config.js"
71
+ });
72
+
73
+ let results = await elev.toJSON();
74
+ let [result] = results;
75
+
76
+ t.is(result.content.trim(), `<!doctype html>
77
+ <html lang="en">
78
+ <head>
79
+ <meta charset="utf-8">
80
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
81
+ <meta name="description" content>
82
+ <title></title>
83
+ <style></style>
84
+ <script></script>
85
+ </head>
86
+ <body>
87
+ HELLO
88
+ HELLO
89
+ WHO IS THIS
90
+ hi
91
+ <span>HELLO FROM FRONT MATTER</span>
92
+
93
+ <style></style>
94
+ <script></script>
95
+
96
+ </body>
97
+ </html>`);
98
+ });
99
+
100
+
101
+ test("Page with front matter no-import components (relative to input path)", async t => {
102
+ let elev = new Eleventy("./test/sample-page-global-components-relative-to-inputpath/page.webc", "./test/sample-page-global-components-relative-to-inputpath/_site", {
103
+ configPath: "./test/sample-page-global-components-relative-to-inputpath/eleventy.config.js"
104
+ });
105
+
106
+ let results = await elev.toJSON();
107
+ let [result] = results;
108
+
109
+ t.is(result.content.trim(), `<!doctype html>
110
+ <html lang="en">
111
+ <head>
112
+ <meta charset="utf-8">
113
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
114
+ <meta name="description" content>
115
+ <title></title>
116
+ <style></style>
117
+ <script></script>
118
+ </head>
119
+ <body>
120
+ HELLO
121
+ HELLO
122
+ WHO IS THIS
123
+ hi
124
+ <span>HELLO FROM FRONT MATTER</span>
125
+
126
+ <style></style>
127
+ <script></script>
128
+
129
+ </body>
130
+ </html>`);
131
+ });