Skip to content

Add ESM support to WebC: swap to use import-module-string instead of node-retrieve-globals#229

Merged
zachleat merged 16 commits into
mainfrom
226
Aug 5, 2025
Merged

Add ESM support to WebC: swap to use import-module-string instead of node-retrieve-globals#229
zachleat merged 16 commits into
mainfrom
226

Conversation

@zachleat

@zachleat zachleat commented Aug 5, 2025

Copy link
Copy Markdown
Member

Fixes #226

  • Breaking: Now requires an export default in both webc:type="render" and webc:type="js" nodes.
  • Breaking: Drops support for CommonJS module.exports in webc:type="render"
  • webc:type="render" and webc:type="js" now use the same code path behind the scenes and are interchangeable.
  • More straightforward use of data: adds a default data argument to webc:type="js" and webc:type="render" default functions: export default function(data) {}
  • Better ESM: adds support for both import and require to webc:type="render" and webc:type="js" nodes (previously only require was supported)

Examples of new export default requirements:

<script webc:type="js">
+export default function() {
  this.alwaysBlue(\`hello\`);
+}
</script>
<script webc:type="js">
+export default function(context) {
-  this.alwaysBlue(\`hello\`);
+  context.alwaysBlue(\`hello\`);
+}
</script>
<script webc:type="render">
-function() {
+export default function() {
  this.alwaysBlue(\`hello\`);
}
</script>
@zachleat zachleat added this to the WebC v0.12.0 milestone Aug 5, 2025
@zachleat zachleat merged commit 8829bb5 into main Aug 5, 2025
12 checks passed
@zachleat zachleat deleted the 226 branch August 5, 2025 22:02
@zachleat zachleat changed the title Swap to use import-module-string instead of node-retrieve-globals Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant