Description
TLDR: refactor the current project setup with a Netzo()
entrypoint function in netzo.ts
into the regular fresh project structure, with a regular netzo()
fresh plugin to mount everything.
Context
In the spirit of aligning more to fresh, it is best to return to the default fresh project structure with a dev.ts
, main.ts
and a netzo.config.ts
(extends the regular fresh.config.ts
). We actually had it this way before, but we abstracted it away into a single netzo.ts
for developer convenience (simpler project structure) and greater control (e.g. enforcing certain plugins). Going back to a netzo.config.ts
would align netzo more with fresh, without sacrificing much DX. To do so, I see 3 alternatives:
1) Separate plugins
This has the least DX, but more modularity, encouraging the plugin ecosystem to grow. Downside is that there is innevitable dependency between certain netzo plugins (by design, to ease the setup, e.g. components depend on unocss
being enabled) and this modularity decreases the ability to enforce certain plugins depending on others. That being said, explicit is always better than implicity, and this could be solved easily by simply documenting it.
import { auth } from "netzo/core/auth/mod.ts"
import { api } from "netzo/core/api/mod.ts"
import { unocss } from "netzo/core/unocss/mod.ts"
export default defineConfig({
plugins: [
auth({...}),
api({...}),
unocss({...}),
]
});
2) Separate plugins (with barrell file)
Same as above, with an additional barrel file import for DX convenience (despite perf issues with barrell files, this is opt-in so it's ok to offer it).
import * as netzo from "netzo/core/mod.ts"
export default defineConfig({
plugins: [
netzo.auth({...}),
netzo.api({...}),
netzo.unocss({...}),
]
});
3) Single plugin
This allows enforcing certain functionalities required by netzo (e.g. platform features like auto-loading remote environmnet variables) and also since some modules depend on others (e.g. components depend on unocss
being enabled).
import * as netzo from "netzo/core/mod.ts"
export default defineConfig({
plugins: [
netzo({
auth: {...},
api: {...},
unocss: {...},
})
]
});
Related
Additionally, simplifying the project structure and fresh server should ideally be done upstream in fresh-land.
- Simplify Fresh Server denoland/fresh#1487
- Plugin API changes denoland/fresh#2288
- feat: remote islands denoland/fresh#2301
- feat: pluginify blog denoland/saaskit#660
fresh.gen.ts
file is also planned for removal