fix: errors in plugin fixture + improve island docs (#2109)

This commit is contained in:
Marvin Hagemeister
2023-12-01 12:21:10 +01:00
committed by GitHub
parent 054ffbb44a
commit bd372b9535
4 changed files with 30 additions and 11 deletions
+19 -6
View File
@@ -169,11 +169,24 @@ A very basic example can be found
### Islands ### Islands
You can create islands that get loaded and rendered like normal Islands from plugins can be loaded by specifying a list of file paths in your
[islands](/docs/concepts/islands). 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 ```tsx my-island-plugin.ts
filenames. The intent is to somewhat mimic the manifest file. import { Plugin } from "$fresh/server.ts";
A very basic example can be found export default function myIslandPlugin(): Plugin {
[here](https://github.com/denoland/fresh/blob/main/tests/fixture_plugin/utils/route-plugin.ts). return {
name: "my-island-plugin",
islands: {
baseLocation: import.meta.url,
paths: [
"./plugin/MyPluginIsland.tsx",
"./plugin/OtherPluginIsland.tsx",
],
},
};
}
```
+5 -5
View File
@@ -257,13 +257,13 @@ export async function extractRoutes(
for (const plugin of config.plugins || []) { for (const plugin of config.plugins || []) {
if (!plugin.islands) continue; if (!plugin.islands) continue;
const base = dirname(plugin.islands.baseLocation); 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 module = await import(full);
const fileNameWithExt = basename(full); const name = sanitizeIslandName(basename(full, extname(full)));
const fileName = fileNameWithExt.replace(extname(fileNameWithExt), "");
processedIslands.push({ processedIslands.push({
name: sanitizeIslandName(fileName), name,
path: full, path: full,
module, module,
}); });
+3
View File
@@ -0,0 +1,3 @@
.body {
color: black;
}
+3
View File
@@ -0,0 +1,3 @@
.body {
color: red;
}