Skip to content

Commit 1b6a86e

Browse files
Add comprehensive rxconfig plugins documentation and update Tailwind docs (#1518)
* Add comprehensive rxconfig plugins documentation and update Tailwind docs - Add new plugins.md documentation covering plugin architecture, built-in plugins, and custom plugin creation - Update Tailwind documentation to emphasize plugin-based configuration approach - Add plugins page to Advanced Onboarding sidebar navigation - Include migration guidance from legacy tailwind config to plugin system - Document SitemapPlugin, TailwindV3Plugin, and TailwindV4Plugin with examples Co-Authored-By: [email protected] <[email protected]> * Address PR feedback: prioritize TailwindV4Plugin over TailwindV3Plugin - Update all examples to use TailwindV4Plugin as the primary/recommended option - Reorder plugin sections to list TailwindV4Plugin before TailwindV3Plugin - Update language to position V4 as default choice for new projects - Remove legacy configuration section from Tailwind docs (removed in 0.8) - Maintain backward compatibility information for existing projects Co-Authored-By: [email protected] <[email protected]> * Address additional PR feedback: remove legacy tailwind config and move plugins to API Reference - Remove '(Recommended)' from tailwind.md title - plugin approach is the only way - Remove 'Disabling Tailwind' section - users should just not use the plugin - Update Custom Theme section to use TailwindV4Plugin instead of tailwind= config - Move plugins.md from Advanced Onboarding to API Reference section - Create corresponding Python page file for API Reference integration - Update sidebar navigation to reflect new organization - Remove all remaining references to legacy tailwind= configuration Addresses all feedback from @masenf on PR #1518 Co-Authored-By: [email protected] <[email protected]> * Fix technical inaccuracies in documentation per adhami3310 feedback - Fix sitemap plugin examples to use context={'sitemap': {...}} syntax - Correct migration section to show actual legacy vs plugin differences - Remove incorrect require() statement about ESM usage - Add back brief section about disabling Tailwind Co-Authored-By: [email protected] <[email protected]> * Move legacy tailwind info to the tailwind page * update launch config for reflex-enterprise compatibility * Move Plugin Architecture section to bottom of page This makes more sense for people interested in implementing a custom plugin, so place it above the custom plugin example. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Masen Furer <[email protected]>
1 parent b727e52 commit 1b6a86e

File tree

5 files changed

+348
-21
lines changed

5 files changed

+348
-21
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"configurations": [
77
{
88
"name": "Reflex Web",
9-
"type": "python",
9+
"type": "debugpy",
1010
"request": "launch",
1111
"module": "reflex",
1212
"args": "run",
1313
"justMyCode": true,
1414
"cwd": "${workspaceFolder}",
15+
"env": {"CI": "1"},
1516
}
1617
]
1718
}

docs/api-reference/plugins.md

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
```python exec
2+
import reflex as rx
3+
from pcweb.pages.docs import advanced_onboarding
4+
```
5+
6+
# Plugins
7+
8+
Reflex supports a plugin system that allows you to extend the framework's functionality during the compilation process. Plugins can add frontend dependencies, modify build configurations, generate static assets, and perform custom tasks before compilation.
9+
10+
## Configuring Plugins
11+
12+
Plugins are configured in your `rxconfig.py` file using the `plugins` parameter:
13+
14+
```python
15+
import reflex as rx
16+
17+
config = rx.Config(
18+
app_name="my_app",
19+
plugins=[
20+
rx.plugins.SitemapPlugin(),
21+
rx.plugins.TailwindV4Plugin(),
22+
],
23+
)
24+
```
25+
26+
## Built-in Plugins
27+
28+
Reflex comes with several built-in plugins that provide common functionality.
29+
30+
### SitemapPlugin
31+
32+
The `SitemapPlugin` automatically generates a sitemap.xml file for your application, which helps search engines discover and index your pages.
33+
34+
```python
35+
import reflex as rx
36+
37+
config = rx.Config(
38+
app_name="my_app",
39+
plugins=[
40+
rx.plugins.SitemapPlugin(),
41+
],
42+
)
43+
```
44+
45+
The sitemap plugin automatically includes all your app's routes. For dynamic routes or custom configuration, you can add sitemap metadata to individual pages:
46+
47+
```python
48+
@rx.page(route="/blog/[slug]", context={"sitemap": {"changefreq": "weekly", "priority": 0.8}})
49+
def blog_post():
50+
return rx.text("Blog post content")
51+
52+
@rx.page(route="/about", context={"sitemap": {"changefreq": "monthly", "priority": 0.5}})
53+
def about():
54+
return rx.text("About page")
55+
```
56+
57+
The sitemap configuration supports the following options:
58+
- `loc`: Custom URL for the page (required for dynamic routes)
59+
- `lastmod`: Last modification date (datetime object)
60+
- `changefreq`: How frequently the page changes (`"always"`, `"hourly"`, `"daily"`, `"weekly"`, `"monthly"`, `"yearly"`, `"never"`)
61+
- `priority`: Priority of this URL relative to other URLs (0.0 to 1.0)
62+
63+
### TailwindV4Plugin
64+
65+
The `TailwindV4Plugin` provides support for Tailwind CSS v4, which is the recommended version for new projects and includes performance improvements and new features.
66+
67+
```python
68+
import reflex as rx
69+
70+
# Basic configuration
71+
config = rx.Config(
72+
app_name="my_app",
73+
plugins=[
74+
rx.plugins.TailwindV4Plugin(),
75+
],
76+
)
77+
```
78+
79+
You can customize the Tailwind configuration by passing a config dictionary:
80+
81+
```python
82+
import reflex as rx
83+
84+
tailwind_config = {
85+
"theme": {
86+
"extend": {
87+
"colors": {
88+
"brand": {
89+
"50": "#eff6ff",
90+
"500": "#3b82f6",
91+
"900": "#1e3a8a",
92+
}
93+
}
94+
}
95+
},
96+
"plugins": ["@tailwindcss/typography"],
97+
}
98+
99+
config = rx.Config(
100+
app_name="my_app",
101+
plugins=[
102+
rx.plugins.TailwindV4Plugin(tailwind_config),
103+
],
104+
)
105+
```
106+
107+
### TailwindV3Plugin
108+
109+
The `TailwindV3Plugin` integrates Tailwind CSS v3 into your Reflex application. While still supported, TailwindV4Plugin is recommended for new projects.
110+
111+
```python
112+
import reflex as rx
113+
114+
# Basic configuration
115+
config = rx.Config(
116+
app_name="my_app",
117+
plugins=[
118+
rx.plugins.TailwindV3Plugin(),
119+
],
120+
)
121+
```
122+
123+
You can customize the Tailwind configuration by passing a config dictionary:
124+
125+
```python
126+
import reflex as rx
127+
128+
tailwind_config = {
129+
"theme": {
130+
"extend": {
131+
"colors": {
132+
"primary": "#3b82f6",
133+
"secondary": "#64748b",
134+
}
135+
}
136+
},
137+
"plugins": ["@tailwindcss/typography", "@tailwindcss/forms"],
138+
}
139+
140+
config = rx.Config(
141+
app_name="my_app",
142+
plugins=[
143+
rx.plugins.TailwindV3Plugin(tailwind_config),
144+
],
145+
)
146+
```
147+
148+
## Plugin Management
149+
150+
### Default Plugins
151+
152+
Some plugins are enabled by default. Currently, the `SitemapPlugin` is enabled automatically. If you want to disable a default plugin, use the `disable_plugins` parameter:
153+
154+
```python
155+
import reflex as rx
156+
157+
config = rx.Config(
158+
app_name="my_app",
159+
disable_plugins=["reflex.plugins.sitemap.SitemapPlugin"],
160+
)
161+
```
162+
163+
### Plugin Order
164+
165+
Plugins are executed in the order they appear in the `plugins` list. This can be important if plugins have dependencies on each other or modify the same files.
166+
167+
```python
168+
import reflex as rx
169+
170+
config = rx.Config(
171+
app_name="my_app",
172+
plugins=[
173+
rx.plugins.TailwindV4Plugin(), # Runs first
174+
rx.plugins.SitemapPlugin(), # Runs second
175+
],
176+
)
177+
```
178+
179+
180+
## Plugin Architecture
181+
182+
All plugins inherit from the base `Plugin` class and can implement several lifecycle methods:
183+
184+
```python
185+
class Plugin:
186+
def get_frontend_development_dependencies(self, **context) -> list[str]:
187+
"""Get NPM packages required by the plugin for development."""
188+
return []
189+
190+
def get_frontend_dependencies(self, **context) -> list[str]:
191+
"""Get NPM packages required by the plugin."""
192+
return []
193+
194+
def get_static_assets(self, **context) -> Sequence[tuple[Path, str | bytes]]:
195+
"""Get static assets required by the plugin."""
196+
return []
197+
198+
def get_stylesheet_paths(self, **context) -> Sequence[str]:
199+
"""Get paths to stylesheets required by the plugin."""
200+
return []
201+
202+
def pre_compile(self, **context) -> None:
203+
"""Called before compilation to perform custom tasks."""
204+
pass
205+
```
206+
207+
### Creating Custom Plugins
208+
209+
You can create custom plugins by inheriting from the base `Plugin` class:
210+
211+
```python
212+
from reflex.plugins.base import Plugin
213+
from pathlib import Path
214+
215+
class CustomPlugin(Plugin):
216+
def get_frontend_dependencies(self, **context):
217+
return ["[email protected]"]
218+
219+
def pre_compile(self, **context):
220+
# Custom logic before compilation
221+
print("Running custom plugin logic...")
222+
223+
# Add a custom task
224+
context["add_save_task"](self.create_custom_file)
225+
226+
def create_custom_file(self):
227+
return "public/custom.txt", "Custom content"
228+
```
229+
230+
Then use it in your configuration:
231+
232+
```python
233+
import reflex as rx
234+
from my_plugins import CustomPlugin
235+
236+
config = rx.Config(
237+
app_name="my_app",
238+
plugins=[
239+
CustomPlugin(),
240+
],
241+
)
242+
```

0 commit comments

Comments
 (0)