Skip to content

Commit aa30bbf

Browse files
committed
chore: update docs
1 parent 35f70f6 commit aa30bbf

File tree

4 files changed

+128
-5
lines changed

4 files changed

+128
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
3+
.DS_Store

docs/content/3.plugin/1.index.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ description: How use the plugin
44
navigation.icon: i-lucide-unplug
55
---
66

7-
The `@reactmos/cli` leverages `vite-plugin-react-modules` to manage module configurations.
7+
The `reactmos` leverages `vite-plugin-react-modules` to manage module configurations.
8+
9+
You might be wondering: Why use Reactmos if I can just use the plugin?
10+
11+
Well, if you use the plugin, it won’t be possible to run each module individually.
12+
13+
You can just create a SPA that will extend other modules. But the modules can’t run in isolation without the main SPA.
14+
15+
## Steps to use
816

917
If you already have a React SPA set up with Vite, you can simply add the plugin to start working with modules.
1018

packages/reactmos/README.md

+112-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,119 @@
1-
# Reactmos
1+
# Reactmos (REACT MOduleS)
22

3-
Create extendable React SPA projects!
3+
Reactmos is a small project, primarily a conceptual approach, inspired by [Nuxt Layers](https://nuxt.com/docs/getting-started/layers) for React.
44

5-
## Usage
5+
> [!NOTE]
6+
> This project is a Work In Progress and currently supports only Single Page Applications (SPA).
67
8+
See [documentation](https://reactmos.dev)
9+
10+
## CLI
11+
12+
We provide a CLI to help run the development server and build the final bundle.
13+
14+
## Reactmos
15+
16+
Reactmos serves as the core of the application and acts as the entry point for Vite.
17+
18+
### Modules
19+
20+
This is where you will develop your application and extend other modules.
21+
22+
To create a new module, simply run:
23+
24+
```sh
25+
pnpm create reactmos <module-name>
26+
```
27+
28+
#### Configuration
29+
30+
See more in `packages/cli/src/types.ts`
31+
32+
```ts
33+
const moduleConfig: ModuleConfig = {
34+
moduleName: 'module-boilerplate',
35+
/**
36+
* Root component of the application.
37+
* If not provided, Reactmos will use the root component
38+
* from the first extended module that defines one.
39+
* If no extended module provides a root component,
40+
* the default from the entry point will be used.
41+
*/
42+
root: App,
43+
routes: () => {
44+
return [
45+
{
46+
path: '/welcome',
47+
Component: Welcome,
48+
},
49+
];
50+
},
51+
hooks: {
52+
'app:beforeRender': () => {
53+
console.log('Before render')
54+
}
55+
}
56+
}
57+
```
58+
59+
### Extending Modules
60+
61+
To extend another module, just add its package name to the `extends` field in `module.config.ts`:
62+
63+
```ts
64+
export default {
65+
extends: ['module-to-extend']
66+
}
767
```
8-
pnpm create reactmos <project-name>
68+
69+
You can also use relative path to other module directory
70+
71+
```ts
72+
export default {
73+
extends: ['../module-to-extend']
74+
}
75+
```
76+
77+
### Lifecycle Hooks
78+
79+
Reactmos provides several lifecycle hooks:
80+
81+
1. **`app:afterBoot`** - Called after the CLI registers all module routes and hooks. Used by the entry point to mount the application.
82+
2. **`app:init`** - Called before the entry point retrieves `App.tsx`, which serves as the root of the application.
83+
3. **`app:beforeRender`** - Called after `App.tsx` is retrieved but before calling `render` from `createRoot`.
84+
4. **`app:afterRender`** - Called after `createRoot` executes `render`.
85+
86+
You can use `app:afterBoot` to create new hooks within your application:
87+
88+
```ts
89+
import { hooks } from 'reactmos';
90+
91+
// Register a new hook called 'hello'
92+
hooks.hook('hello', () => {
93+
console.log('Hello, World!');
94+
});
95+
96+
// Call the 'hello' hook
97+
hooks.callHook('hello');
998
```
1099

100+
For more details, see [hookable](https://github.com/unjs/hookable).
101+
102+
### Components
103+
104+
Reactmos provides a `<Pages />` component that represents all registered routes. You can use it in your `App.tsx` root component.
105+
106+
### Utility Functions
107+
108+
Reactmos also provides the following functions:
109+
110+
1. **`getRoutes`** - Retrieves all registered routes.
111+
2. **`getRoot`** - Returns the `App.tsx` root component.
112+
3. **`getExtras(moduleName)`** - Returns extra configuration in module configs
113+
114+
## Roadmap
11115

116+
- [x] Support for extending routes/pages
117+
- [x] Support for extending the `public` directory
118+
- [x] Share custom configs with other modules
119+
- [ ] Additional extension capabilities?

packages/reactmos/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"name": "reactmos",
33
"version": "0.5.0",
4+
"author": "Igor Jacaúna <[email protected]>",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/igorjacauna/reactmos"
8+
},
49
"type": "module",
510
"main": "src/index.ts",
611
"files": [

0 commit comments

Comments
 (0)