@modern-js/main-doc 2.58.2 → 2.59.0
Sign up to get free protection for your applications and to get access to all the features.
- package/docs/en/apis/app/runtime/core/use-loader.mdx +1 -1
- package/docs/en/community/blog/_meta.json +1 -6
- package/docs/en/components/deploy.mdx +1 -1
- package/docs/en/components/init-app.mdx +0 -1
- package/docs/en/components/init-rspack-app.mdx +0 -1
- package/docs/en/components/ssr-monitor.mdx +3 -0
- package/docs/en/configure/_meta.json +1 -1
- package/docs/en/configure/app/output/ssg.mdx +52 -141
- package/docs/en/configure/app/tools/swc.mdx +1 -1
- package/docs/en/configure/app/tools/tailwindcss.mdx +1 -1
- package/docs/en/guides/advanced-features/_meta.json +0 -8
- package/docs/en/guides/advanced-features/bff/_meta.json +1 -6
- package/docs/en/guides/advanced-features/rsbuild-plugin.mdx +2 -2
- package/docs/en/guides/advanced-features/rspack-start.mdx +7 -22
- package/docs/en/guides/basic-features/_meta.json +31 -9
- package/docs/en/guides/basic-features/css/_meta.json +1 -0
- package/docs/en/guides/basic-features/css/css-in-js.mdx +34 -0
- package/docs/en/guides/basic-features/{css-modules.mdx → css/css-modules.mdx} +0 -4
- package/docs/en/guides/basic-features/css/css.mdx +25 -0
- package/docs/en/guides/basic-features/{css.mdx → css/tailwindcss.mdx} +5 -66
- package/docs/en/guides/basic-features/data/_meta.json +1 -4
- package/docs/en/guides/basic-features/data/data-fetch.mdx +134 -235
- package/docs/en/guides/basic-features/data/data-write.mdx +66 -77
- package/docs/en/guides/basic-features/debug/_meta.json +1 -0
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +57 -0
- package/docs/en/guides/{advanced-features → basic-features/debug}/using-storybook.mdx +2 -0
- package/docs/en/guides/basic-features/render/_meta.json +1 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +208 -0
- package/docs/en/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +38 -50
- package/docs/en/guides/basic-features/render/ssr.mdx +301 -0
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +230 -0
- package/docs/en/guides/basic-features/routes.mdx +275 -263
- package/docs/en/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/en/guides/basic-features/static-assets.mdx +1 -1
- package/docs/en/guides/basic-features/testing/_meta.json +1 -0
- package/docs/en/guides/basic-features/testing/cypress.mdx +95 -0
- package/docs/en/guides/basic-features/testing/jest.mdx +148 -0
- package/docs/en/guides/basic-features/testing/playwright.mdx +111 -0
- package/docs/en/guides/basic-features/testing/vitest.mdx +100 -0
- package/docs/en/guides/concept/_meta.json +1 -4
- package/docs/en/guides/concept/entries.mdx +78 -47
- package/docs/en/guides/get-started/_meta.json +1 -7
- package/docs/en/guides/get-started/introduction.mdx +1 -1
- package/docs/en/guides/get-started/quick-start.mdx +1 -2
- package/docs/en/guides/get-started/tech-stack.mdx +4 -6
- package/docs/en/guides/get-started/upgrade.mdx +16 -2
- package/docs/en/guides/topic-detail/framework-plugin/_meta.json +1 -1
- package/docs/en/guides/topic-detail/generator/_meta.json +1 -1
- package/docs/en/guides/topic-detail/generator/create/_meta.json +1 -5
- package/docs/en/guides/topic-detail/generator/create/config.mdx +0 -10
- package/docs/en/guides/topic-detail/generator/create/use.mdx +0 -1
- package/docs/en/guides/topic-detail/generator/new/_meta.json +1 -5
- package/docs/en/guides/topic-detail/generator/plugin/_meta.json +1 -1
- package/docs/en/guides/troubleshooting/_meta.json +1 -6
- package/docs/en/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +1 -1
- package/docs/zh/community/blog/_meta.json +1 -6
- package/docs/zh/components/deploy.mdx +1 -1
- package/docs/zh/components/init-app.mdx +0 -1
- package/docs/zh/components/init-rspack-app.mdx +0 -1
- package/docs/zh/components/ssr-monitor.mdx +3 -0
- package/docs/zh/configure/_meta.json +1 -1
- package/docs/zh/configure/app/output/ssg.mdx +49 -139
- package/docs/zh/configure/app/tools/swc.mdx +1 -1
- package/docs/zh/configure/app/tools/tailwindcss.mdx +1 -1
- package/docs/zh/guides/advanced-features/_meta.json +0 -8
- package/docs/zh/guides/advanced-features/bff/_meta.json +1 -6
- package/docs/zh/guides/advanced-features/rsbuild-plugin.mdx +2 -2
- package/docs/zh/guides/advanced-features/rspack-start.mdx +8 -24
- package/docs/zh/guides/basic-features/_meta.json +31 -9
- package/docs/zh/guides/basic-features/css/_meta.json +1 -0
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +34 -0
- package/docs/zh/guides/basic-features/css/css.mdx +25 -0
- package/docs/zh/guides/basic-features/{css.mdx → css/tailwindcss.mdx} +3 -64
- package/docs/zh/guides/basic-features/data/_meta.json +1 -4
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +98 -214
- package/docs/zh/guides/basic-features/data/data-write.mdx +54 -55
- package/docs/zh/guides/basic-features/debug/_meta.json +1 -0
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +57 -0
- package/docs/zh/guides/{advanced-features → basic-features/debug}/using-storybook.mdx +1 -1
- package/docs/zh/guides/basic-features/render/_meta.json +1 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +210 -0
- package/docs/zh/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +16 -26
- package/docs/zh/guides/basic-features/render/ssr.mdx +309 -0
- package/docs/zh/guides/{advanced-features/ssr/stream.mdx → basic-features/render/streaming-ssr.mdx} +22 -37
- package/docs/zh/guides/basic-features/routes.mdx +252 -237
- package/docs/zh/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/zh/guides/basic-features/static-assets.mdx +2 -6
- package/docs/zh/guides/basic-features/testing/_meta.json +1 -0
- package/docs/zh/guides/basic-features/testing/cypress.mdx +95 -0
- package/docs/zh/guides/basic-features/testing/jest.mdx +148 -0
- package/docs/zh/guides/basic-features/testing/playwright.mdx +112 -0
- package/docs/zh/guides/basic-features/testing/vitest.mdx +100 -0
- package/docs/zh/guides/concept/_meta.json +1 -4
- package/docs/zh/guides/concept/entries.mdx +80 -58
- package/docs/zh/guides/get-started/_meta.json +1 -7
- package/docs/zh/guides/get-started/introduction.mdx +2 -2
- package/docs/zh/guides/get-started/quick-start.mdx +1 -2
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -10
- package/docs/zh/guides/get-started/upgrade.mdx +15 -1
- package/docs/zh/guides/topic-detail/framework-plugin/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/generator/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/generator/create/_meta.json +1 -5
- package/docs/zh/guides/topic-detail/generator/create/config.mdx +0 -10
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +0 -1
- package/docs/zh/guides/topic-detail/generator/new/_meta.json +1 -5
- package/docs/zh/guides/topic-detail/generator/plugin/_meta.json +1 -1
- package/docs/zh/guides/troubleshooting/_meta.json +1 -6
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/i18n.json +16 -4
- package/package.json +6 -6
- package/rspress.config.ts +1 -1
- package/src/components/ContentCard/index.tsx +1 -1
- package/src/components/Sandpack/index.tsx +1 -1
- package/src/components/ShowcaseList/index.tsx +1 -1
- package/src/i18n/index.ts +1 -1
- package/src/pages/index.tsx +2 -2
- package/docs/en/apis/app/hooks/config/storybook.mdx +0 -37
- package/docs/en/guides/advanced-features/ssg.mdx +0 -116
- package/docs/en/guides/advanced-features/ssr/_meta.json +0 -5
- package/docs/en/guides/advanced-features/ssr/index.mdx +0 -23
- package/docs/en/guides/advanced-features/ssr/stream.mdx +0 -248
- package/docs/en/guides/advanced-features/ssr/usage.mdx +0 -341
- package/docs/en/guides/advanced-features/ssr.mdx +0 -555
- package/docs/zh/apis/app/hooks/config/storybook.mdx +0 -38
- package/docs/zh/guides/advanced-features/ssg.mdx +0 -116
- package/docs/zh/guides/advanced-features/ssr/_meta.json +0 -5
- package/docs/zh/guides/advanced-features/ssr/index.mdx +0 -23
- package/docs/zh/guides/advanced-features/ssr/usage.mdx +0 -329
- /package/docs/en/guides/basic-features/{mock.mdx → debug/mock.mdx} +0 -0
- /package/docs/en/guides/basic-features/{proxy.mdx → debug/proxy.mdx} +0 -0
- /package/docs/en/guides/basic-features/{json-files.mdx → static-assets/json-files.mdx} +0 -0
- /package/docs/en/guides/basic-features/{svg-assets.mdx → static-assets/svg-assets.mdx} +0 -0
- /package/docs/en/guides/basic-features/{wasm-assets.mdx → static-assets/wasm-assets.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{css-modules.mdx → css/css-modules.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{mock.mdx → debug/mock.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{proxy.mdx → debug/proxy.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{json-files.mdx → static-assets/json-files.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{svg-assets.mdx → static-assets/svg-assets.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{wasm-assets.mdx → static-assets/wasm-assets.mdx} +0 -0
@@ -52,7 +52,7 @@ function useLoader(loaderFn: LoaderFn, options: Options): ReturnData;
|
|
52
52
|
- `initialData`: the initial data before the first execution,.
|
53
53
|
- `skip`: when the value is `true`, the function does not execute.
|
54
54
|
- `params`: when the result of the `params` serialization changes, the function is re-executed. `params` is also passed in as the second argument of the function.
|
55
|
-
- `static`: when the value is `true`, `useLoader` is used for [SSG](/guides/
|
55
|
+
- `static`: when the value is `true`, `useLoader` is used for [SSG](/guides/basic-features/render/ssg).
|
56
56
|
|
57
57
|
### Return Value
|
58
58
|
|
@@ -1 +1 @@
|
|
1
|
-
After local
|
1
|
+
After local develop, you can refer to the [Deployment](/guides/basic-features/deploy.html) section to deploy the project to the server.
|
@@ -4,7 +4,6 @@
|
|
4
4
|
? Please select the type of project you want to create: Web App
|
5
5
|
? Please select the programming language: TS
|
6
6
|
? Please select the package manager: pnpm
|
7
|
-
? Please select the bundler: webpack
|
8
7
|
```
|
9
8
|
|
10
9
|
After create the project, Modern.js will automatically install dependencies and create a git repository.
|
@@ -4,46 +4,24 @@ title: ssg
|
|
4
4
|
|
5
5
|
# output.ssg
|
6
6
|
|
7
|
-
- **Type:** `boolean` | `object`
|
8
|
-
- **Default:** `undefined`
|
7
|
+
- **Type:** `boolean` | `object`
|
8
|
+
- **Default Value:** `undefined`
|
9
9
|
|
10
|
-
|
10
|
+
Configuration to enable the application’s SSG (Static Site Generation) feature.
|
11
11
|
|
12
|
-
:::
|
13
|
-
This configuration
|
12
|
+
:::tip Enabling SSG
|
13
|
+
This configuration takes effect only when SSG is enabled. Please read the [Static Site Generation](/guides/basic-features/render/ssg) documentation to understand how to enable SSG and its use cases.
|
14
14
|
:::
|
15
15
|
|
16
|
-
:::info
|
17
|
-
|
18
|
-
|
16
|
+
:::info Recommended Reading
|
17
|
+
The SSG feature is closely related to routing. It is recommended to understand the [routing solution](/guides/basic-features/routes) before using SSG.
|
19
18
|
:::
|
20
19
|
|
21
|
-
##
|
22
|
-
|
23
|
-
### Single Entry
|
24
|
-
|
25
|
-
When the configuration is set to `true`, the SSG of all entries will be enabled by default.
|
26
|
-
|
27
|
-
For **self-controlled routing**, the root route of the entry will be rendered. For **convention routing**, every route in the entry will be rendered.
|
28
|
-
|
29
|
-
For example, the `src/` directory has the following file structure that satisfies **conventional routing**:
|
30
|
-
|
31
|
-
```bash
|
32
|
-
.
|
33
|
-
├── src
|
34
|
-
│ └── routes
|
35
|
-
│ ├── layout.tsx
|
36
|
-
│ ├── page.tsx
|
37
|
-
│ └── user
|
38
|
-
│ ├── layout.tsx
|
39
|
-
│ ├── page.tsx
|
40
|
-
│ └── profile
|
41
|
-
│ └── page.tsx
|
42
|
-
```
|
20
|
+
## Boolean Type
|
43
21
|
|
44
|
-
|
22
|
+
When this configuration is set to `true`, the SSG feature will be enabled for all entries by default. For **manual routing**, the root route of the entry will be rendered. For **conventional routing**, each route in the entry will be rendered.
|
45
23
|
|
46
|
-
```
|
24
|
+
```js
|
47
25
|
export default defineConfig({
|
48
26
|
output: {
|
49
27
|
ssg: true,
|
@@ -51,39 +29,20 @@ export default defineConfig({
|
|
51
29
|
});
|
52
30
|
```
|
53
31
|
|
54
|
-
|
55
|
-
|
56
|
-
For example the following **self-controlled routing**:
|
57
|
-
|
58
|
-
import SelfRouteExample from "@site-docs/components/self-route-example";
|
59
|
-
|
60
|
-
<SelfRouteExample />
|
61
|
-
|
62
|
-
Also using the above configuration, after executing `pnpm run build`, only the entry route `/` will generate the rendered HTML.
|
32
|
+
`output.ssg` can also be configured per entry, with the rules for effective configurations determined by the entry's routing method.
|
63
33
|
|
64
|
-
|
65
|
-
|
66
|
-
`output.ssg` can also be configured according to the entries, and the rules that the configuration takes effect are also determined by the entries routing method.
|
67
|
-
|
68
|
-
For example the following directory structure:
|
34
|
+
For example, given the following directory structure, there are conventional routing entry `entryA` and manual routing entry `entryB`:
|
69
35
|
|
70
36
|
```bash
|
71
37
|
.
|
72
|
-
|
73
|
-
|
74
|
-
│
|
75
|
-
|
76
|
-
|
77
|
-
│ │ └── user
|
78
|
-
│ │ ├── layout.tsx
|
79
|
-
│ │ ├── page.tsx
|
80
|
-
│ │ └── profile
|
81
|
-
│ │ └── page.tsx
|
82
|
-
│ └── entryB
|
83
|
-
│ └── App.tsx
|
38
|
+
└── src
|
39
|
+
├── entryA
|
40
|
+
│ └── routes
|
41
|
+
└── entryB
|
42
|
+
└── App.tsx
|
84
43
|
```
|
85
44
|
|
86
|
-
|
45
|
+
You can specify different SSG configurations for `entryA` and `entryB`:
|
87
46
|
|
88
47
|
```js
|
89
48
|
export default defineConfig({
|
@@ -96,107 +55,59 @@ export default defineConfig({
|
|
96
55
|
});
|
97
56
|
```
|
98
57
|
|
99
|
-
### Configure Route
|
100
|
-
|
101
|
-
As mentioned above, **Self-Controlled Routing** only enables SSG configuration for entries route by default.
|
102
|
-
|
103
|
-
Set specific routes in `output.ssg` can tell Modern.js to enable the SSG of these client side routes. For example, the content of the above `src/App.tsx` file is:
|
104
|
-
|
105
|
-
<SelfRouteExample />
|
106
|
-
|
107
|
-
|
108
|
-
When set like this in `modern.config.[jt]s`, the `/about` route will also enable SSG:
|
109
|
-
|
110
|
-
```js
|
111
|
-
export default defineConfig({
|
112
|
-
output: {
|
113
|
-
ssg: {
|
114
|
-
routes: ['/', '/about'],
|
115
|
-
},
|
116
|
-
},
|
117
|
-
});
|
118
|
-
```
|
119
|
-
|
120
|
-
Modern.js will automatically concat the complete URL according to the entry and hand it over to the SSG plugin to complete the rendering.
|
121
|
-
|
122
|
-
Request headers can also be configured for specific entries or routes, for example:
|
123
|
-
|
124
|
-
```js
|
125
|
-
export default defineConfig({
|
126
|
-
output: {
|
127
|
-
ssg: {
|
128
|
-
headers: {},
|
129
|
-
routes: [
|
130
|
-
'/',
|
131
|
-
{
|
132
|
-
url: '/about',
|
133
|
-
headers: {},
|
134
|
-
},
|
135
|
-
],
|
136
|
-
},
|
137
|
-
},
|
138
|
-
});
|
139
|
-
```
|
140
|
-
|
141
58
|
:::info
|
142
|
-
|
143
|
-
|
59
|
+
For more information on the default behavior of **conventional routing** and **manual routing** after enabling SSG, please read [Static Site Generation](/guides/basic-features/render/ssg).
|
144
60
|
:::
|
145
61
|
|
146
|
-
|
62
|
+
## Object Type
|
147
63
|
|
148
|
-
|
64
|
+
When the value type is `Object`, the following attributes can be configured.
|
149
65
|
|
150
|
-
|
66
|
+
### Configuration Type
|
151
67
|
|
152
|
-
```bash
|
153
|
-
.
|
154
|
-
├── src
|
155
|
-
│ └── routes
|
156
|
-
│ ├── layout.tsx
|
157
|
-
│ ├── page.tsx
|
158
|
-
│ └── user
|
159
|
-
│ ├── layout.tsx
|
160
|
-
│ ├── page.tsx
|
161
|
-
│ └── profile
|
162
|
-
│ └── page.tsx
|
163
|
-
```
|
164
|
-
|
165
|
-
You can set this to disable the default behavior of a client-side route:
|
166
68
|
|
167
|
-
```
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
69
|
+
```ts
|
70
|
+
type SSGRouteOptions = string | {
|
71
|
+
url: string;
|
72
|
+
params?: Record<string, any>[];
|
73
|
+
headers?: Record<string, any>;
|
74
|
+
};
|
75
|
+
|
76
|
+
type SSGOptions = {
|
77
|
+
preventDefault?: string[];
|
78
|
+
headers?: Record<string, any>;
|
79
|
+
routes?: SSGRouteOptions[];
|
80
|
+
};
|
175
81
|
```
|
176
82
|
|
177
|
-
###
|
83
|
+
### Example
|
178
84
|
|
179
|
-
|
85
|
+
In the example configuration below, SSG will render the pages corresponding to the `/`, `/about`, and `/user/:id` routes.
|
180
86
|
|
181
|
-
|
87
|
+
For the `/user/:id` route, `cookies` will be added to the request headers, and the `id` in `params` will be replaced with `modernjs`.
|
182
88
|
|
183
|
-
```
|
89
|
+
```ts title="modern.config.ts"
|
184
90
|
export default defineConfig({
|
185
91
|
output: {
|
186
92
|
ssg: {
|
187
93
|
routes: [
|
94
|
+
'/',
|
95
|
+
'/about',
|
188
96
|
{
|
189
97
|
url: '/user/:id',
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
98
|
+
headers: {
|
99
|
+
cookies: "name=modernjs"
|
100
|
+
},
|
101
|
+
params: [{
|
102
|
+
id: 'modernjs',
|
103
|
+
}],
|
104
|
+
}
|
196
105
|
],
|
197
|
-
}
|
198
|
-
}
|
106
|
+
}
|
107
|
+
}
|
199
108
|
});
|
200
109
|
```
|
201
110
|
|
202
|
-
|
111
|
+
:::note
|
112
|
+
The configuration method for multiple entries is the same as for a single entry, so it will not be explained further here.
|
113
|
+
:::
|
@@ -19,7 +19,7 @@ When using Rspack as the bundler, SWC will be used for transpiling and compressi
|
|
19
19
|
|
20
20
|
## Used in Rspack mode
|
21
21
|
|
22
|
-
You can set the options of [builtin:swc-loader](https://
|
22
|
+
You can set the options of [builtin:swc-loader](https://rspack.dev/guide/features/builtin-swc-loader) through `tools.swc`.
|
23
23
|
|
24
24
|
```
|
25
25
|
import { defineConfig } from '@modern-js/app-tools';
|
@@ -23,7 +23,7 @@ Used to modify the configuration of [Tailwind CSS](https://tailwindcss.com/docs/
|
|
23
23
|
|
24
24
|
Before using `tools.tailwindcss`, you need to enable the Tailwind CSS plugin for Modern.js.
|
25
25
|
|
26
|
-
Please refer to the section [Using Tailwind CSS](/guides/basic-features/css
|
26
|
+
Please refer to the section [Using Tailwind CSS](/guides/basic-features/css/tailwindcss) for instructions on how to enable it.
|
27
27
|
|
28
28
|
### Function Type
|
29
29
|
|
@@ -7,13 +7,6 @@
|
|
7
7
|
"collapsed": true
|
8
8
|
},
|
9
9
|
"code-split",
|
10
|
-
{
|
11
|
-
"type": "dir",
|
12
|
-
"name": "ssr",
|
13
|
-
"label": "use-ssr",
|
14
|
-
"collapsed": true
|
15
|
-
},
|
16
|
-
"ssg",
|
17
10
|
"compatibility",
|
18
11
|
"eslint",
|
19
12
|
"low-level",
|
@@ -21,6 +14,5 @@
|
|
21
14
|
"build-performance",
|
22
15
|
"inline-assets",
|
23
16
|
"optimize-bundle",
|
24
|
-
"using-storybook",
|
25
17
|
"web-server"
|
26
18
|
]
|
@@ -41,8 +41,8 @@ Here are the official Rsbuild plugins built into Modern.js:
|
|
41
41
|
| [CSS Minimizer Plugin](https://github.com/rspack-contrib/rsbuild-plugin-css-minimizer) | Used to customize CSS minimizer, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
|
42
42
|
| [Pug Plugin](https://github.com/rspack-contrib/rsbuild-plugin-pug) | Provides support for the Pug template engine | [tools.pug](/configure/app/tools/pug.html) |
|
43
43
|
| [Rem Plugin](https://github.com/rspack-contrib/rsbuild-plugin-rem) | Implements the rem adaptive layout for mobile pages | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
|
44
|
-
| [YAML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/json-files.html#toml-file) |
|
45
|
-
| [TOML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/json-files.html#yaml-file) |
|
44
|
+
| [YAML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/static-assets/json-files.html#toml-file) |
|
45
|
+
| [TOML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/static-assets/json-files.html#yaml-file) |
|
46
46
|
|
47
47
|
### Un-builtin Plugins
|
48
48
|
|
@@ -8,13 +8,13 @@ import Rspack from '@modern-js/builder-doc/docs/en/shared/rspackTip.mdx';
|
|
8
8
|
|
9
9
|
<Rspack />
|
10
10
|
|
11
|
-
**Modern.js provides out-of-the-box Rspack support**, so you can switch between the stable
|
11
|
+
**Modern.js provides out-of-the-box Rspack support**, so you can switch between the stable webpack and the faster Rspack.
|
12
12
|
|
13
13
|
This document will show you how to enable Rspack build mode in Modern.js.
|
14
14
|
|
15
15
|
## Initializing an Rspack project
|
16
16
|
|
17
|
-
The Modern.js
|
17
|
+
The Modern.js new project has enabled Rspack by default. Just execute [Initialize Project](/guides/get-started/quick-start.html#initialize) to create an Rspack project:
|
18
18
|
|
19
19
|
import InitRspackApp from '@site-docs-en/components/init-rspack-app';
|
20
20
|
|
@@ -22,16 +22,9 @@ import InitRspackApp from '@site-docs-en/components/init-rspack-app';
|
|
22
22
|
|
23
23
|
After the project is created, you can experience the project by running `pnpm run dev`. For more project information, please refer to [Quick Start](/guides/get-started/quick-start.html).
|
24
24
|
|
25
|
-
:::tip
|
26
|
-
When using Rspack as the bundler, the following Features are temporarily unavailable as some of the capabilities are still under development and we will provide support in the future.
|
27
|
-
|
28
|
-
- The usage of [useLoader](/guides/basic-features/data/data-fetch.html) in Client Side Rendering
|
29
|
-
|
30
|
-
:::
|
31
|
-
|
32
25
|
## Enable Rspack build
|
33
26
|
|
34
|
-
Since Modern.js MAJOR_VERSION.
|
27
|
+
Since Modern.js MAJOR_VERSION.59.0, you can enable Rspack build by add the following configuration in `modern.config.ts`:
|
35
28
|
|
36
29
|
```diff title=modern.config.ts
|
37
30
|
import { appTools, defineConfig } from '@modern-js/app-tools';
|
@@ -39,14 +32,14 @@ import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
39
32
|
export default defineConfig({
|
40
33
|
plugins: [
|
41
34
|
appTools({
|
42
|
-
+ bundler: '
|
35
|
+
+ bundler: 'rspack',
|
43
36
|
}),
|
44
37
|
],
|
45
38
|
});
|
46
39
|
```
|
47
40
|
|
48
41
|
:::tip
|
49
|
-
If your current version is lower than MAJOR_VERSION.
|
42
|
+
If your current version is lower than MAJOR_VERSION.59.0, you can upgrade by executing `npx modern upgrade`.
|
50
43
|
:::
|
51
44
|
|
52
45
|
import RspackPrecautions from '@modern-js/builder-doc/docs/en/shared/rspackPrecautions.md';
|
@@ -77,15 +70,9 @@ export default {
|
|
77
70
|
};
|
78
71
|
```
|
79
72
|
|
80
|
-
:::tip
|
81
|
-
After turning on the Rspack build capability, there are currently a small number of configurations that are not supported in Rspack, such as [source.moduleScopes](/configure/app/source/module-scopes), [security.sri](/configure/app/security/sri) etc.
|
82
|
-
|
83
|
-
For unsupported configurations, we have marked `Bundler: only support webpack` or `Bundler: only support Rspack` in the document. Please refer to the specific configuration introduction.
|
84
|
-
:::
|
85
|
-
|
86
73
|
## Modify transpile configuration
|
87
74
|
|
88
|
-
Modern.js uses Rspack [builtin:swc-loader](https://
|
75
|
+
Modern.js uses Rspack [builtin:swc-loader](https://rspack.dev/guide/features/builtin-swc-loader) for code translation in Rspack mode.
|
89
76
|
|
90
77
|
Modern.js has provided a more convenient configuration for the common configuration of `builtin:swc-loader`, such as: configuring the component library to import it on demand through [source.transformImport](/configure/app/source/transform-import).
|
91
78
|
|
@@ -148,9 +135,7 @@ If you need to use the nightly/canary version of Rspack, the package name of the
|
|
148
135
|
"@rspack/plugin-react-refresh": "npm:@rspack/plugin-react-refresh-canary@nightly"
|
149
136
|
},
|
150
137
|
"peerDependencyRules": {
|
151
|
-
"allowAny": [
|
152
|
-
"@rspack/*"
|
153
|
-
]
|
138
|
+
"allowAny": ["@rspack/*"]
|
154
139
|
}
|
155
140
|
}
|
156
141
|
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
[
|
2
|
-
"css",
|
3
2
|
"routes",
|
4
3
|
{
|
5
4
|
"type": "dir",
|
@@ -7,16 +6,39 @@
|
|
7
6
|
"label": "data-solution",
|
8
7
|
"collapsed": true
|
9
8
|
},
|
9
|
+
{
|
10
|
+
"type": "dir",
|
11
|
+
"name": "render",
|
12
|
+
"label": "rendering",
|
13
|
+
"collapsed": true
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"type": "dir",
|
17
|
+
"name": "css",
|
18
|
+
"label": "css-solution",
|
19
|
+
"collapsed": true
|
20
|
+
},
|
21
|
+
"html",
|
22
|
+
{
|
23
|
+
"type": "dir",
|
24
|
+
"name": "static-assets",
|
25
|
+
"label": "static-assets",
|
26
|
+
"collapsed": true
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"type": "dir",
|
30
|
+
"name": "debug",
|
31
|
+
"label": "debug",
|
32
|
+
"collapsed": true
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"type": "dir",
|
36
|
+
"name": "testing",
|
37
|
+
"label": "testing",
|
38
|
+
"collapsed": true
|
39
|
+
},
|
10
40
|
"alias",
|
11
|
-
"mock",
|
12
|
-
"proxy",
|
13
41
|
"env-vars",
|
14
|
-
"html",
|
15
42
|
"output-files",
|
16
|
-
"static-assets",
|
17
|
-
"svg-assets",
|
18
|
-
"json-files",
|
19
|
-
"wasm-assets",
|
20
|
-
"css-modules",
|
21
43
|
"deploy"
|
22
44
|
]
|
@@ -0,0 +1 @@
|
|
1
|
+
["css", "css-modules", "css-in-js", "tailwindcss"]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Using CSS-in-JS
|
2
|
+
|
3
|
+
CSS-in-JS is a technique that allows you to write CSS styles in JS files.
|
4
|
+
|
5
|
+
Modern.js integrates the popular CSS-in-JS implementation library [styled-components](https://styled-components.com/), which uses the new JavaScript feature [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write component CSS styles. You can directly import the API of [styled-components](https://styled-components.com/) from `@modern-js/runtime/styled` for use.
|
6
|
+
|
7
|
+
When you need to write a `div` component with an internal font color of red, you can implement it as follows:
|
8
|
+
|
9
|
+
```js
|
10
|
+
import styled from '@modern-js/runtime/styled';
|
11
|
+
|
12
|
+
const RedDiv = styled.div`
|
13
|
+
color: red;
|
14
|
+
`;
|
15
|
+
```
|
16
|
+
|
17
|
+
If you need to dynamically set component styles based on the component's `props`, for example, the `primary` property of `props` is `true`, the button color is white, otherwise it is red, you can implement the code as follows:
|
18
|
+
|
19
|
+
```js
|
20
|
+
import styled from '@modern-js/runtime/styled';
|
21
|
+
|
22
|
+
const Button = styled.button`
|
23
|
+
color: ${props => (props.primary ? 'white' : 'red')};
|
24
|
+
font-size: 1em;
|
25
|
+
`;
|
26
|
+
```
|
27
|
+
|
28
|
+
For more usage of styled-components, please refer to [styled-components official website](https://styled-components.com/).
|
29
|
+
|
30
|
+
Modern.js integrates Babel's [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) plugin internally, and you can configure the plugin through [tools.styledComponents](/configure/app/tools/styled-components).
|
31
|
+
|
32
|
+
:::tip
|
33
|
+
If you need to use other CSS-in-JS libraries such as [styled-jsx](https://www.npmjs.com/package/styled-jsx) and [Emotion](https://emotion.sh/), you need to install the corresponding dependencies first. For specific usage, please refer to the library's official website.
|
34
|
+
:::
|
@@ -1,7 +1,3 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 14
|
3
|
-
---
|
4
|
-
|
5
1
|
# Use CSS Modules
|
6
2
|
|
7
3
|
[CSS Modules](https://github.com/css-modules/css-modules) allows us to write CSS code in a modular way, and these styles can be imported and used in JavaScript files. Using CSS Modules can automatically generate unique class names, isolate styles between different modules, and avoid class name conflicts.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# Styling
|
6
|
+
|
7
|
+
Modern.js has built-in a variety of commonly used CSS solutions, including Less / Sass / Stylus preprocessors, PostCSS, CSS Modules, CSS-in-JS, and Tailwind CSS.
|
8
|
+
|
9
|
+
## Using Less, Sass and Stylus
|
10
|
+
|
11
|
+
Modern.js has built-in popular community CSS preprocessors, including Less and Sass.
|
12
|
+
|
13
|
+
By default, you don't need to configure Less and Sass. If you have custom loader configuration requirements, you can set them up by configuring [tools.less](/configure/app/tools/less) and [tools.sass](/configure/app/tools/sass).
|
14
|
+
|
15
|
+
You can also use Stylus in Modern.js by installing the Stylus plugin provided by Rsbuild. For usage, please refer to [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus).
|
16
|
+
|
17
|
+
## Using PostCSS
|
18
|
+
|
19
|
+
Modern.js has built-in [PostCSS](https://postcss.org/) to transform CSS code.
|
20
|
+
|
21
|
+
Please refer to [Rsbuild - Using PostCSS](https://rsbuild.dev/guide/basic/css-usage#using-postcss) for detailed usage.
|
22
|
+
|
23
|
+
## Using Uno CSS
|
24
|
+
|
25
|
+
Please read the [Rsbuild - Using UnoCSS](https://rsbuild.dev/zh/guide/basic/unocss) for detailed usage.
|