|
| 1 | +# 5stack Plugin — Hello World |
| 2 | + |
| 3 | +The smallest complete [5stack plugin](https://docs.5stack.gg/plugins): a Vue |
| 4 | +Module Federation remote that renders **natively inside the 5stack panel** — |
| 5 | +same sidebar, header, theme, and login. Copy this repo as the starting point for |
| 6 | +your own. |
| 7 | + |
| 8 | +```sh |
| 9 | +npm install |
| 10 | +npm run dev # standalone preview at :5173 with a fake dev user |
| 11 | +npm run build # -> dist/ |
| 12 | +npm run preview # serve dist/ at :4173 with CORS, for testing in a real panel |
| 13 | +``` |
| 14 | + |
| 15 | +## What makes it a plugin |
| 16 | + |
| 17 | +| File | Role | |
| 18 | +| --- | --- | |
| 19 | +| `src/App.vue` | Your UI. Receives the logged-in `user` as a prop. | |
| 20 | +| `vite.config.ts` | Exposes `./App` as a Federation remote; declares shared singletons. | |
| 21 | +| `public/5stack-plugin.json` | The manifest the panel auto-detects. | |
| 22 | +| `tailwind.config.js` | Pulls in the `@5stack/ui` preset so you inherit 5stack theming. | |
| 23 | +| `src/main.ts` | Standalone dev entry — **not** used when embedded in the panel. | |
| 24 | + |
| 25 | +## Try it against a running panel |
| 26 | + |
| 27 | +```sh |
| 28 | +npm run build && npm run preview |
| 29 | +``` |
| 30 | + |
| 31 | +Then in the panel: **Settings → Application → Plugins → Add**, paste |
| 32 | +`http://localhost:4173`, hit **Detect**, toggle **Enabled**, and save. Make sure |
| 33 | +the **Plugins** master switch is on. Your page appears in the sidebar at |
| 34 | +`/apps/hello`. |
| 35 | + |
| 36 | +`npm run preview` already sends the CORS and `no-store` headers the panel needs. |
| 37 | +When you deploy for real, your own web server must do the same — see |
| 38 | +[Deploying](https://docs.5stack.gg/plugins/deploying). |
| 39 | + |
| 40 | +## Renaming it |
| 41 | + |
| 42 | +Federation scopes share one flat global namespace across every plugin an |
| 43 | +operator installs, so `hello` will collide — pick something specific: |
| 44 | + |
| 45 | +| Rename | In | |
| 46 | +| --- | --- | |
| 47 | +| `name: "hello"` | `vite.config.ts` | |
| 48 | +| `"scope": "hello"` | `public/5stack-plugin.json` (must equal the above) | |
| 49 | +| `"slug": "hello"` | `public/5stack-plugin.json` (your URL: `/apps/<slug>`) | |
| 50 | +| `[data-hello-plugin]` | `tailwind.config.js` and `src/App.vue` (must match) | |
| 51 | + |
| 52 | +## Two things that are easy to get wrong |
| 53 | + |
| 54 | +**Version lockstep.** Every package in `shared` is `requiredVersion: false`, so a |
| 55 | +version that disagrees with the panel's does not error — it silently loads a |
| 56 | +second copy and breaks reactivity. Pin the same versions the panel uses. |
| 57 | + |
| 58 | +**Style scoping.** This plugin's CSS is injected at runtime *after* the panel's, |
| 59 | +so unscoped utilities would override host chrome. `important: |
| 60 | +"[data-hello-plugin]"` in `tailwind.config.js` scopes every utility under the |
| 61 | +wrapper in `App.vue`. Keep both in sync, and prefer named theme tokens over |
| 62 | +arbitrary values like `min-h-[60vh]`. |
| 63 | + |
| 64 | +## Docs |
| 65 | + |
| 66 | +Full guide: **https://docs.5stack.gg/plugins** |
| 67 | + |
| 68 | +- [Getting Started](https://docs.5stack.gg/plugins/getting-started) |
| 69 | +- [The Manifest](https://docs.5stack.gg/plugins/manifest) |
| 70 | +- [Module Federation](https://docs.5stack.gg/plugins/module-federation) |
| 71 | +- [Styling](https://docs.5stack.gg/plugins/styling) |
| 72 | +- [Components](https://docs.5stack.gg/plugins/components) |
| 73 | +- [Backend & Auth](https://docs.5stack.gg/plugins/backend) |
| 74 | +- [Deploying](https://docs.5stack.gg/plugins/deploying) |
| 75 | + |
| 76 | +For a fuller example with a backend and a database, see the |
| 77 | +[inventory plugin](https://github.com/lukepolo/5stack-inventory-plugin). |
0 commit comments