@@ -112,10 +112,21 @@ function islandsPlugin(eleventyConfig) {
112112 * @param {"hydrate" | "static" | "client" } mode
113113 */
114114 function createIslandShortcode ( mode ) {
115+ /**
116+ * @param {string | { src: string, export: string } } src
117+ * @param {any[] } args
118+ */
115119 return async function ( src , ...args ) {
120+ let name = "default" ;
116121 let props = argsToProps ( args ) ;
117122 let html = "" ;
118123
124+ // Handle imports with named exports
125+ if ( typeof src === "object" ) {
126+ name = src . export ;
127+ src = src . src ;
128+ }
129+
119130 // It's important that we use the version of the file inside the islands
120131 // dir rather than the one inside _site/islands, because there's no
121132 // guarantee that it will have been copied over before this shortcode
@@ -134,7 +145,7 @@ function islandsPlugin(eleventyConfig) {
134145 // version gets us a different one).
135146 let { h } = await import ( "preact" ) ;
136147 let { renderToString } = await import ( "preact-render-to-string" ) ;
137- html = renderToString ( h ( mod . default , props ) ) ;
148+ html = renderToString ( h ( mod [ name ] , props ) ) ;
138149 }
139150
140151 if ( mode === "static" ) {
@@ -151,7 +162,7 @@ function islandsPlugin(eleventyConfig) {
151162<div data-island-id="${ id } ">${ html } </div>
152163<script async type="module">
153164 import { h, hydrate } from "preact";
154- import component from "${ src } ";
165+ import { ${ name } as component } from "${ src } ";
155166 let element = document.querySelector(\`[data-island-id="${ id } "]\`);
156167 hydrate(h(component, ${ JSON . stringify ( props ) } ), element);
157168</script>
0 commit comments