@modern-js/main-doc 0.0.0-next-20221227040741 → 0.0.0-next-20221227140603
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -22
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/index_.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/pages.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/routes.md +86 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +31 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/tailwindcss.md +16 -22
- package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/code-split.md +27 -22
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/tailwindcss.md +30 -35
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +399 -0
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/html.md +5 -5
- package/package.json +3 -3
- package/zh/apis/app/hooks/src/index_.md +1 -1
- package/zh/apis/app/hooks/src/pages.md +1 -1
- package/zh/apis/app/hooks/src/routes.md +89 -0
- package/zh/configure/app/dev/with-master-app.md +32 -0
- package/zh/configure/app/runtime/master-app.md +16 -2
- package/zh/configure/app/tools/tailwindcss.md +16 -23
- package/zh/guides/advanced-features/bff/function.md +24 -2
- package/zh/guides/advanced-features/code-split.md +26 -22
- package/zh/guides/basic-features/css/tailwindcss.md +31 -35
- package/zh/guides/basic-features/data-fetch.md +6 -6
- package/zh/guides/basic-features/html.md +5 -5
- package/zh/guides/basic-features/routes.md +37 -3
- package/zh/guides/topic-detail/framework-plugin/implement.md +54 -6
- package/zh/components/micro-master-manifest-config.md +0 -15
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
@@ -1,35 +1,33 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
-
## 0.0.0-next-
|
3
|
+
## 0.0.0-next-20221227140603
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
-
-
|
7
|
+
- 7879e8f71: refactor: remove enableModernMode config
|
8
8
|
|
9
9
|
refactor: 不再支持 enableModernMode 配置项
|
10
10
|
|
11
|
-
-
|
12
|
-
chore: 修改 plugin-garfish 文档
|
13
|
-
- 5927355ee1: feat: develop documentation directly with main-doc
|
11
|
+
- 5927355ee: feat: develop documentation directly with main-doc
|
14
12
|
feat: 直接使用 main-doc 包开发文档
|
15
|
-
-
|
13
|
+
- ebf899fb5: feat(app-tools): support configure builder plugins
|
16
14
|
|
17
15
|
feat(app-tools): 支持配置 builder 插件
|
18
16
|
|
19
|
-
-
|
17
|
+
- 1ef69374b: feat: support update main-doc when package build or website build
|
20
18
|
feat: 支持在包发布和官网发布时,更新 main-doc 包
|
21
|
-
- Updated dependencies [
|
22
|
-
- Updated dependencies [
|
23
|
-
- Updated dependencies [
|
24
|
-
- Updated dependencies [
|
25
|
-
- Updated dependencies [
|
26
|
-
- Updated dependencies [
|
27
|
-
- Updated dependencies [
|
28
|
-
- Updated dependencies [
|
29
|
-
- Updated dependencies [
|
30
|
-
- Updated dependencies [
|
31
|
-
- Updated dependencies [
|
32
|
-
- Updated dependencies [
|
33
|
-
- Updated dependencies [
|
34
|
-
- Updated dependencies [
|
35
|
-
- @modern-js/builder-doc@0.0.0-next-
|
19
|
+
- Updated dependencies [2bc090c08]
|
20
|
+
- Updated dependencies [f96a72521]
|
21
|
+
- Updated dependencies [57077b2c6]
|
22
|
+
- Updated dependencies [2ff6167be]
|
23
|
+
- Updated dependencies [309f08bdf]
|
24
|
+
- Updated dependencies [5402fdb0c]
|
25
|
+
- Updated dependencies [10d08a480]
|
26
|
+
- Updated dependencies [5d67c26cd]
|
27
|
+
- Updated dependencies [af4422d67]
|
28
|
+
- Updated dependencies [dda38c9c3]
|
29
|
+
- Updated dependencies [812913ccd]
|
30
|
+
- Updated dependencies [3fae2d03b]
|
31
|
+
- Updated dependencies [df41d71ad]
|
32
|
+
- Updated dependencies [14b712da8]
|
33
|
+
- @modern-js/builder-doc@0.0.0-next-20221227140603
|
@@ -0,0 +1,86 @@
|
|
1
|
+
---
|
2
|
+
title: routes/
|
3
|
+
sidebar_position: 2
|
4
|
+
---
|
5
|
+
|
6
|
+
The entry identifier when the application uses file system-based routing.
|
7
|
+
|
8
|
+
When the project structure is of type `Routes directory entry`, the files in the `src/routes` directory are parsed to get the client-side routing configuration. See [Routing by convention](/docs/guides/basic-features/routes) for more details on usage.
|
9
|
+
|
10
|
+
|
11
|
+
Any `layout.[tj]sx` and `page.[tj]sx` under `src/routes` will be used as a route to the application:
|
12
|
+
```bash {3}
|
13
|
+
.
|
14
|
+
└── routes
|
15
|
+
├── layout.tsx
|
16
|
+
├── page.tsx
|
17
|
+
└── user
|
18
|
+
├── layout.tsx
|
19
|
+
└── page.tsx
|
20
|
+
```
|
21
|
+
|
22
|
+
## basic example
|
23
|
+
|
24
|
+
The directory names in the `routes` directory will be used as a mapping of the route url, where `layout.tsx` is used as the layout component and `page.tsx` as the content component, which is a leaf node of the whole route, for example the following directory structure:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
.
|
28
|
+
└── routes
|
29
|
+
├── page.tsx
|
30
|
+
└── user
|
31
|
+
└── page.tsx
|
32
|
+
```
|
33
|
+
|
34
|
+
The following two routes are produced:
|
35
|
+
- `/`
|
36
|
+
- `/user`
|
37
|
+
|
38
|
+
## Dynamic Route
|
39
|
+
|
40
|
+
If the directory name of the route file is named with `[]`, the generated route will be used as a dynamic route. For example, the following file directories:
|
41
|
+
|
42
|
+
```
|
43
|
+
└── routes
|
44
|
+
├── [id]
|
45
|
+
│ └── page.tsx
|
46
|
+
├── blog
|
47
|
+
│ └── page.tsx
|
48
|
+
└── page.tsx
|
49
|
+
```
|
50
|
+
|
51
|
+
The `routes/[id]/page.tsx` file will be converted to a `/:id` route. All `/xxx` will match that route, except for the `/blog` route, which can be matched exactly.
|
52
|
+
|
53
|
+
In the component, you can get the corresponding parameters by [useParams](/docs/apis/app/runtime/router/#useparams).
|
54
|
+
|
55
|
+
In the loader, params will be used as input to [loader](/docs/guides/basic-features/data-fetch#loader-function), and the corresponding parameters can be retrieved through the property `params`.
|
56
|
+
|
57
|
+
## Layout component
|
58
|
+
|
59
|
+
As in the example below, you can add a common layout component for all routing components by adding `layout.tsx`
|
60
|
+
|
61
|
+
```bash
|
62
|
+
.
|
63
|
+
└── routes
|
64
|
+
├── layout.tsx
|
65
|
+
├── page.tsx
|
66
|
+
└── user
|
67
|
+
├── layout.tsx
|
68
|
+
└── page.tsx
|
69
|
+
```
|
70
|
+
|
71
|
+
You can represent child components in layout components by using `<Outlet>`:
|
72
|
+
```tsx title=routes/layout.tsx
|
73
|
+
import { Link, Outlet, useLoaderData } from '@modern-js/runtime/router';
|
74
|
+
|
75
|
+
export default () => {
|
76
|
+
return (
|
77
|
+
<>
|
78
|
+
<Outlet></Outlet>
|
79
|
+
</>
|
80
|
+
)
|
81
|
+
}
|
82
|
+
```
|
83
|
+
|
84
|
+
:::note
|
85
|
+
`<Outlet>` is a new API in React Router 6, see [Outlet] for details(https://reactrouter.com/en/main/components/outlet#outlet).
|
86
|
+
:::
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: withMasterApp
|
3
|
+
---
|
4
|
+
|
5
|
+
# dev.withMasterApp
|
6
|
+
|
7
|
+
* Type: `Object`
|
8
|
+
* Default: `null`
|
9
|
+
|
10
|
+
When the project is a micro-front-end sub-application, you can use the `withMasterApp` configuration to enable the sub-application debugging mode.
|
11
|
+
|
12
|
+
:::caution Caution
|
13
|
+
When using child app debugging mode, you should first ensure that the main app has online debugging mode turned on.
|
14
|
+
:::
|
15
|
+
|
16
|
+
```js title=modern.config.js
|
17
|
+
export default defineConfig({
|
18
|
+
dev: {
|
19
|
+
withMasterApp: {
|
20
|
+
//the path of the main application
|
21
|
+
moduleApp: 'https://www.masterApp.com',
|
22
|
+
//name of the subapplication
|
23
|
+
moduleName: 'Contact'
|
24
|
+
}
|
25
|
+
}
|
26
|
+
})
|
27
|
+
```
|
28
|
+
|
29
|
+
- moduleApp: `string` Online address of the main application.
|
30
|
+
- moduleName: `Contact` The name of the child app (needs to match the module name registered in the main app)。
|
31
|
+
|
@@ -4,38 +4,32 @@ title: tools.tailwindcss
|
|
4
4
|
sidebar_label: tailwindcss
|
5
5
|
---
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
- Type: `Object | Function`
|
8
|
+
- Default: See configuration details below.
|
9
9
|
|
10
10
|
<details>
|
11
11
|
<summary>TailwindCSS configuration details</summary>
|
12
12
|
|
13
13
|
```js
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
removeDeprecatedGapUtilities: false,
|
28
|
-
purgeLayersByDefault: true,
|
29
|
-
defaultLineHeights: false,
|
30
|
-
standardFontWeights: false,
|
31
|
-
},
|
32
|
-
theme: source.designSystem // Use source.design System configuration as Tailwind CSS Theme configuration
|
33
|
-
}
|
14
|
+
const tailwind = {
|
15
|
+
content: [
|
16
|
+
'./config/html/**/*.html',
|
17
|
+
'./config/html/**/*.ejs',
|
18
|
+
'./config/html/**/*.hbs',
|
19
|
+
'./src/**/*.js',
|
20
|
+
'./src/**/*.jsx',
|
21
|
+
'./src/**/*.ts',
|
22
|
+
'./src/**/*.tsx',
|
23
|
+
'./storybook/**/*',
|
24
|
+
],
|
25
|
+
theme: source.designSystem, // Use source.design System configuration as Tailwind CSS Theme configuration
|
26
|
+
};
|
34
27
|
```
|
35
28
|
|
36
29
|
:::tip Tips
|
37
30
|
More about: <a href="https://tailwindcss.com/docs/configuration" target="_blank">TailwindCSS configuration</a>。
|
38
31
|
:::
|
32
|
+
|
39
33
|
</details>
|
40
34
|
|
41
35
|
When the value is of type `Object`, rhe configuration corresponding to [TailwindCSS](https://tailwindcss.com/docs/configuration) is merged with the default configuration through `Object.assign`.
|
@@ -5,6 +5,10 @@ sidebar_position: 6
|
|
5
5
|
|
6
6
|
Code Split is a common way to optimizing front-end resource loading. This doc will introduce three methods supported by Modern.js:
|
7
7
|
|
8
|
+
:::info
|
9
|
+
When you use Modern.js [Conventional routing](/docs/guides/basic-features/routes#conventional-routing), by default it will do code splitting based on routing components, wrapping `Suspense` components, no need to do code splitting by yourself.
|
10
|
+
:::
|
11
|
+
|
8
12
|
- `import`
|
9
13
|
- `React.lazy`
|
10
14
|
- `loadable`
|
@@ -21,32 +25,13 @@ import("./math").then(math => {
|
|
21
25
|
|
22
26
|
The JS modules corresponding to the './math' path will be packaged in a separate JS file.
|
23
27
|
|
24
|
-
## loadable
|
25
|
-
|
26
|
-
use `loadable` API,for example:
|
27
|
-
|
28
|
-
```ts
|
29
|
-
import loadable from '@modern-js/runtime/loadable'
|
30
|
-
|
31
|
-
const OtherComponent = loadable(() => import('./OtherComponent'));
|
32
|
-
|
33
|
-
function MyComponent() {
|
34
|
-
return <OtherComponent />
|
35
|
-
}
|
36
|
-
```
|
37
|
-
|
38
|
-
For detail, see [loadable API](/docs/apis/app/runtime/utility/loadable)。
|
39
|
-
|
40
|
-
:::info
|
41
|
-
SSR is supported out of the box by `loadable`.
|
42
|
-
:::
|
43
28
|
|
44
29
|
## React.lazy
|
45
30
|
|
46
31
|
The officially way provides by React to split component code.
|
47
32
|
|
48
|
-
:::
|
49
|
-
|
33
|
+
:::caution
|
34
|
+
SSR is not supported in React 17 and below, and it is recommended that SSR applications for React 17 use loadable.
|
50
35
|
:::
|
51
36
|
|
52
37
|
```ts
|
@@ -69,4 +54,24 @@ function MyComponent() {
|
|
69
54
|
}
|
70
55
|
```
|
71
56
|
|
72
|
-
For detail, see [React lazy](https://
|
57
|
+
For detail, see [React lazy](https://reactjs.org/docs/code-splitting.html#reactlazy)。
|
58
|
+
|
59
|
+
## loadable
|
60
|
+
|
61
|
+
use `loadable` API,for example:
|
62
|
+
|
63
|
+
```ts
|
64
|
+
import loadable from '@modern-js/runtime/loadable'
|
65
|
+
|
66
|
+
const OtherComponent = loadable(() => import('./OtherComponent'));
|
67
|
+
|
68
|
+
function MyComponent() {
|
69
|
+
return <OtherComponent />
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
For detail, see [loadable API](/docs/apis/app/runtime/utility/loadable)。
|
74
|
+
|
75
|
+
:::info
|
76
|
+
SSR is supported out of the box by `loadable`.
|
77
|
+
:::
|
@@ -4,8 +4,6 @@ sidebar_position: 2
|
|
4
4
|
|
5
5
|
# Tailwind CSS
|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
[Tailwind CSS](https://tailwindcss.com/) is a CSS framework and design system based on Utility Class, which can quickly add common styles to components, and support flexible extension of theme styles. To use [Tailwind CSS](https://tailwindcss.com/) in the Modern.js, just execute `pnpm run new` in the project root directory and turn it on.
|
10
8
|
|
11
9
|
Choose as follows:
|
@@ -23,12 +21,40 @@ import 'tailwindcss/components.css';
|
|
23
21
|
import 'tailwindcss/utilities.css';
|
24
22
|
```
|
25
23
|
|
26
|
-
You can then use the Utility Class provided by Tailwind CSS in each component
|
24
|
+
You can then use the Utility Class provided by Tailwind CSS in each component:
|
25
|
+
|
26
|
+
```tsx
|
27
|
+
const App = () => (
|
28
|
+
<div className="h-12 w-48">
|
29
|
+
<p className="text-xl font-medium text-black">hello world</p>
|
30
|
+
</div>
|
31
|
+
);
|
32
|
+
```
|
27
33
|
|
28
34
|
::: info Additional
|
29
35
|
According to different needs, you can optionally import the CSS files provided by Tailwind CSS. Since the use of `@taiwind` is equivalent to directly importing CSS files, you can refer to the content in the annotate in the [`@tailwind` usage](https://tailwindcss.com/docs/functions-and-directives#tailwind) document for the purpose of the CSS files provided by Tailwind CSS.
|
30
36
|
:::
|
31
37
|
|
38
|
+
## Tailwind CSS version
|
39
|
+
|
40
|
+
Modern.js supports both Tailwind CSS v2 and v3. The framework will recognize the version of `tailwindcss` in the project `package.json` and apply the corresponding configuration. By default, we install Tailwind CSS v3 for you.
|
41
|
+
|
42
|
+
If your project is still using Tailwind CSS v2, we recommend that you upgrade to v3 to support JIT and other capabilities. For the differences between Tailwind CSS v2 and v3 versions, please refer to the following articles:
|
43
|
+
|
44
|
+
- [Tailwind CSS v3.0](https://tailwindcss.com/blog/tailwindcss-v3)
|
45
|
+
- [Upgrade Guide](https://tailwindcss.com/docs/upgrade-guide)
|
46
|
+
|
47
|
+
### Browser Compatibility
|
48
|
+
|
49
|
+
Both Tailwind CSS v2 and v3 do not support IE 11 browsers. For background, please refer to:
|
50
|
+
|
51
|
+
- [Tailwind CSS v3 - Browser Support](https://tailwindcss.com/docs/browser-support).
|
52
|
+
- [Tailwind CSS v2 - Browser Support](https://v2.tailwindcss.com/docs/browser-support)
|
53
|
+
|
54
|
+
If you use Tailwind CSS on IE 11 browser, some styles may not be available, please pay attention.
|
55
|
+
|
56
|
+
## Theme config
|
57
|
+
|
32
58
|
When you need to customize the [theme](https://tailwindcss.com/docs/theme) configuration of Tailwind CSS, you can modify it in the configuration [`source.designSystem`](/docs/configure/app/source/design-system), for example, add a color theme `primary`:
|
33
59
|
|
34
60
|
```typescript title="modern.config.ts"
|
@@ -61,35 +87,4 @@ export default defineConfig({
|
|
61
87
|
});
|
62
88
|
```
|
63
89
|
|
64
|
-
|
65
|
-
|
66
|
-
In the previous chapter, we introduced what CSS-in-JS is and the CSS-in-JS library [styled-components](https://styled-components.com/) commonly used by the community. This section will explain how to use [Tailwind CSS](https://tailwindcss.com/) in CSS with [`Twin`](https://github.com/ben-rogerson/twin.macro). Using [`Twin`](https://github.com/ben-rogerson/twin.macro) makes it easier to use Tailwind CSS in CSS-in-JS code. [`Twin`](https://github.com/ben-rogerson/twin.macro) for its own description is:
|
67
|
-
|
68
|
-
> *Twin blends the magic of Tailwind with the flexibility of css-in-js*
|
69
|
-
|
70
|
-
After enabling the "Tailwind CSS" function, you first need to install the ['Twin'](https://github.com/ben-rogerson/twin.macro) dependency:
|
71
|
-
|
72
|
-
``` bash
|
73
|
-
pnpm add twin.macro -D
|
74
|
-
```
|
75
|
-
|
76
|
-
When the project installs the `twin.macro` dependency, Modern.js detects the dependency and adds twin.macro related configuration to the `baby-plugin-macro` of build-in. So after installing the dependency, there is no need for manual configuration. Here is an example of a simple use of twin.macro:
|
77
|
-
|
78
|
-
``` js
|
79
|
-
import tw from 'twin.macro'
|
80
|
-
|
81
|
-
const Input = tw.input`border hover:border-black`
|
82
|
-
```
|
83
|
-
|
84
|
-
:::tip
|
85
|
-
If a `MacroError: /project/App.tsx` error occurs during runtime, it may be caused by a lack of `twin.macro` dependency.
|
86
|
-
:::
|
87
|
-
|
88
|
-
For more usage, please refer to the [twin.macro](https://github.com/ben-rogerson/twin.macro/blob/master/docs/index.md).
|
89
|
-
|
90
|
-
`twin.macro` reads the `tailwindcss.config.js` files in the project directory by default, or reads the Tailwind CSS configuration via the file path specified by [twin.config](https://github.com/ben-rogerson/twin.macro/blob/master/docs/options.md#options) on the `babel-plugin-macro`. However, these additional configurations are not required in the Modern.js.
|
91
|
-
|
92
|
-
When the Tailwind CSS is configured in the `modern.config.ts` file by [`source.designSystem`](/docs/configure/app/source/design-system) and [`tools.tailwindcss`](/docs/configure/app/tools/tailwindcss), these configurations will also take effect on the `twin.macro`.
|
93
|
-
|
94
|
-
> When configuring Tailwind CSS for a project, the combination of the two configurations [`source.designSystem`](/docs/configure/app/source/design-system) and [`tools.tailwindcss`](/docs/configure/app/tools/tailwindcss) is equivalent to a separate configuration `tailwindcss.config.js` file.
|
95
|
-
> Where [`source.designSystem`](/docs/configure/app/source/design-system) is equivalent to the [`theme`](https://v2.tailwindcss.com/docs/configuration#theme) configuration of Tailwind CSS.
|
90
|
+
> When configuring Tailwind CSS for a project, the combination of the two configurations [source.designSystem](/docs/configure/app/source/design-system) and [tools.tailwindcss](/docs/configure/app/tools/tailwindcss) is equivalent to a separate configuration `tailwindcss.config.js` file. Where [source.designSystem](/docs/configure/app/source/design-system) is equivalent to the [theme](https://v2.tailwindcss.com/docs/configuration#theme) configuration of Tailwind CSS.
|