@@ -112,10 +112,21 @@ function islandsPlugin(eleventyConfig) {
112
112
* @param {"hydrate" | "static" | "client" } mode
113
113
*/
114
114
function createIslandShortcode ( mode ) {
115
+ /**
116
+ * @param {string | { src: string, export: string } } src
117
+ * @param {any[] } args
118
+ */
115
119
return async function ( src , ...args ) {
120
+ let name = "default" ;
116
121
let props = argsToProps ( args ) ;
117
122
let html = "" ;
118
123
124
+ // Handle imports with named exports
125
+ if ( typeof src === "object" ) {
126
+ name = src . export ;
127
+ src = src . src ;
128
+ }
129
+
119
130
// It's important that we use the version of the file inside the islands
120
131
// dir rather than the one inside _site/islands, because there's no
121
132
// guarantee that it will have been copied over before this shortcode
@@ -134,7 +145,7 @@ function islandsPlugin(eleventyConfig) {
134
145
// version gets us a different one).
135
146
let { h } = await import ( "preact" ) ;
136
147
let { renderToString } = await import ( "preact-render-to-string" ) ;
137
- html = renderToString ( h ( mod . default , props ) ) ;
148
+ html = renderToString ( h ( mod [ name ] , props ) ) ;
138
149
}
139
150
140
151
if ( mode === "static" ) {
@@ -151,7 +162,7 @@ function islandsPlugin(eleventyConfig) {
151
162
<div data-island-id="${ id } ">${ html } </div>
152
163
<script async type="module">
153
164
import { h, hydrate } from "preact";
154
- import component from "${ src } ";
165
+ import { ${ name } as component } from "${ src } ";
155
166
let element = document.querySelector(\`[data-island-id="${ id } "]\`);
156
167
hydrate(h(component, ${ JSON . stringify ( props ) } ), element);
157
168
</script>
0 commit comments