Skip to content

Commit 7e57c34

Browse files
feat: #4 upgrade 11ty v3 and adopt ESM (#17)
* feat: #4 upgrade 11ty v3 * docs: #4 update README * update component definition * feat: #4 update dev mode cache busting for ESM * feat: upgrade v6 action checkout
1 parent f787e6a commit 7e57c34

11 files changed

Lines changed: 1726 additions & 4446 deletions

File tree

.eleventy.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const path = require('path');
2-
const { pathToFileURL } = require('url');
3-
const wccPlugin = require('./src/index');
1+
import { wccPlugin } from './src/index.js';
42

5-
module.exports = function(eleventyConfig) {
3+
export default function(eleventyConfig) {
64
eleventyConfig.addPlugin(wccPlugin, {
75
definitions: [
8-
pathToFileURL(path.join(__dirname, './demo/components/greeting.js'))
6+
new URL('./demo/components/greeting.js', import.meta.url)
97
]
108
});
119

.github/workflows/ci-win.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ on: [pull_request]
55
jobs:
66

77
build:
8-
runs-on: ubuntu-18.04
8+
runs-on: ubuntu-latest
99

1010
strategy:
1111
matrix:
12-
node: [14, 16]
12+
node: [22, 24]
1313

1414
steps:
15-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v6
1616
- name: Use Node.js ${{ matrix.node }}
17-
uses: actions/setup-node@v2
17+
uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node }}
2020
- name: Installing project dependencies
@@ -23,9 +23,6 @@ jobs:
2323
- name: Lint
2424
run: |
2525
npm run lint
26-
# - name: Test
27-
# run: |
28-
# yarn test
2926
- name: Build
3027
run: |
31-
npm run clean && npm run build
28+
npm run build

.github/workflows/ci.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ on: [pull_request]
55
jobs:
66

77
build:
8-
runs-on: ubuntu-18.04
8+
runs-on: ubuntu-latest
99

1010
strategy:
1111
matrix:
12-
node: [14, 16]
12+
node: [22, 24]
1313

1414
steps:
15-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v6
1616
- name: Use Node.js ${{ matrix.node }}
17-
uses: actions/setup-node@v2
17+
uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node }}
2020
- name: Installing project dependencies
@@ -23,9 +23,6 @@ jobs:
2323
- name: Lint
2424
run: |
2525
npm run lint
26-
# - name: Test
27-
# run: |
28-
# yarn test
2926
- name: Build
3027
run: |
31-
npm run clean && npm run build
28+
npm run build

.github/workflows/master.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.18.0

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
Install from NPM.
1212

1313
```sh
14-
$ npm install eleventy-plugin-wcc --save-dev
14+
$ npm i -D eleventy-plugin-wcc
1515
```
1616

1717
## Configuration
1818

1919
Add the plugin to your _eleventy.js_ config and provide a [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) for all _top level_ custom element definitions you use.
2020
```js
21-
const path = require('path');
22-
const { pathToFileURL } = require('url');
23-
const wccPlugin = require('./src/index');
21+
import { wccPlugin } from './src/index.js';
2422

2523
module.exports = function(eleventyConfig) {
2624
eleventyConfig.addPlugin(wccPlugin, {
2725
definitions: [
28-
pathToFileURL(path.join(__dirname, './src/js/my-element.js'))
26+
new URL('./src/js/my-element.js', import.meta.url)
2927
]
3028
});
3129
};
@@ -34,16 +32,18 @@ module.exports = function(eleventyConfig) {
3432
## Usage
3533
3634
### 1. Create a Custom Element
35+
3736
Write a custom element like below. In this case, we are using [Declarative Shadow DOM](https://web.dev/declarative-shadow-dom/).
37+
3838
```js
39-
// src/js/greeting.js
39+
// src/components/greeting.js
4040
const template = document.createElement('template');
4141

4242
template.innerHTML = `
4343
<p>Hello from the greeting component!</p>
4444
`;
4545

46-
class GreetingComponent extends HTMLElement {
46+
export default class GreetingComponent extends HTMLElement {
4747
constructor() {
4848
super();
4949
this.attachShadow({ mode: 'open' });
@@ -54,30 +54,27 @@ class GreetingComponent extends HTMLElement {
5454
}
5555
}
5656

57-
module.exports = GreetingComponent; // using module.exports!
58-
5957
customElements.define('x-greeting', GreetingComponent);
6058
```
6159
62-
> **Note**: Since [Eleventy does not support ESM yet](https://github.com/11ty/eleventy/issues/836), you will need to use `module.exports = XXX` instead of `export default XXX` for your definitions.
63-
6460
### 2. Update Configuration
61+
6562
Add your custom element paths to your _.eleventy.js_ config
63+
6664
```js
67-
const path = require('path');
68-
const { pathToFileURL } = require('url');
69-
const wccPlugin = require('eleventy-plugin-wcc');
65+
import { wccPlugin } from './src/index.js';
7066

7167
module.exports = function(eleventyConfig) {
7268
eleventyConfig.addPlugin(wccPlugin, {
7369
definitions: [
74-
pathToFileURL(path.join(__dirname, './src/js/greeting.js'))
70+
new URL('./src/components/my-element.js', import.meta.url)
7571
]
7672
});
7773
};
7874
```
7975
8076
### 3. Use It!
77+
8178
Now in your content or layouts, use the custom element.
8279
```md
8380
<!-- src/index.md -->
@@ -91,13 +88,12 @@ Now in your content or layouts, use the custom element.
9188
Now if you run `eleventy`, you should get an _index.html_ in your _site/_ directory with the custom element content pre-rendered! 🎈
9289
```html
9390
<h2>Hello From 11ty + WCC!</h2>
94-
<p>
95-
<x-greeting>
96-
<template shadowroot="open">
97-
<p>Hello from the greeting component!</p>
98-
</template>
99-
</x-greeting>
100-
</p>
91+
92+
<x-greeting>
93+
<template shadowroot="open">
94+
<p>Hello from the greeting component!</p>
95+
</template>
96+
</x-greeting>
10197
```
10298
10399
## Options

demo/components/greeting.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ template.innerHTML = `
44
<p>Hello from the greeting component!</p>
55
`;
66

7-
class GreetingComponent extends HTMLElement {
7+
export default class GreetingComponent extends HTMLElement {
88
constructor() {
99
super();
1010
this.attachShadow({ mode: 'open' });
@@ -15,6 +15,4 @@ class GreetingComponent extends HTMLElement {
1515
}
1616
}
1717

18-
module.exports = GreetingComponent;
19-
2018
customElements.define('x-greeting', GreetingComponent);

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
skip_processing = true
77

88
[build.environment]
9-
NODE_VERSION = "14.16.0"
9+
NODE_VERSION = "22.18.0"

0 commit comments

Comments
 (0)