Skip to content

Commit

Permalink
fix: errors in plugin fixture + improve island docs (#2109)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Dec 1, 2023
1 parent 054ffbb commit bd372b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
25 changes: 19 additions & 6 deletions docs/canary/concepts/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,24 @@ A very basic example can be found

### Islands

You can create islands that get loaded and rendered like normal
[islands](/docs/concepts/islands).
Islands from plugins can be loaded by specifying a list of file paths in your
plugin. Those files will be treated by Fresh as if they had been placed inside
the `islands/` directory. They will be processed and bundled for the browser in
the same way.

You need to provide the location of your plugin and an array of island
filenames. The intent is to somewhat mimic the manifest file.
```tsx my-island-plugin.ts
import { Plugin } from "$fresh/server.ts";

A very basic example can be found
[here](https://github.com/denoland/fresh/blob/main/tests/fixture_plugin/utils/route-plugin.ts).
export default function myIslandPlugin(): Plugin {
return {
name: "my-island-plugin",
islands: {
baseLocation: import.meta.url,
paths: [
"./plugin/MyPluginIsland.tsx",
"./plugin/OtherPluginIsland.tsx",
],
},
};
}
```
10 changes: 5 additions & 5 deletions src/server/fs_extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ export async function extractRoutes(
for (const plugin of config.plugins || []) {
if (!plugin.islands) continue;
const base = dirname(plugin.islands.baseLocation);
for (const name of plugin.islands.paths) {
const full = join(base, name);

for (const specifier of plugin.islands.paths) {
const full = join(base, specifier);
const module = await import(full);
const fileNameWithExt = basename(full);
const fileName = fileNameWithExt.replace(extname(fileNameWithExt), "");
const name = sanitizeIslandName(basename(full, extname(full)));
processedIslands.push({
name: sanitizeIslandName(fileName),
name,
path: full,
module,
});
Expand Down
3 changes: 3 additions & 0 deletions tests/fixture_plugin/static/print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.body {
color: black;
}
3 changes: 3 additions & 0 deletions tests/fixture_plugin/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.body {
color: red;
}

0 comments on commit bd372b9

Please sign in to comment.