@modern-js/main-doc 2.9.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +27 -0
- package/docs/en/apis/app/hooks/src/server.mdx +1 -28
- package/docs/en/apis/app/runtime/web-server/hook.mdx +1 -3
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +1 -4
- package/docs/en/blog/index.md +8 -0
- package/docs/en/configure/app/output/splitRouteChunks.mdx +20 -0
- package/docs/en/configure/app/source/config-dir.mdx +2 -2
- package/docs/en/configure/app/source/design-system.mdx +2 -2
- package/docs/en/configure/app/source/disable-default-entries.mdx +12 -12
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +3 -4
- package/docs/en/configure/app/source/enable-async-entry.mdx +2 -2
- package/docs/en/configure/app/source/entries-dir.mdx +10 -10
- package/docs/en/configure/app/source/entries.mdx +83 -26
- package/docs/en/configure/app/source/plugin-import.mdx +13 -0
- package/docs/en/configure/app/source/transform-import.mdx +13 -0
- package/docs/en/configure/app/tools/esbuild.mdx +9 -4
- package/docs/en/configure/app/tools/jest.mdx +2 -3
- package/docs/en/configure/app/tools/swc.mdx +6 -2
- package/docs/en/guides/advanced-features/compatibility.mdx +1 -0
- package/docs/en/guides/advanced-features/rspack-start.mdx +1 -1
- package/docs/en/guides/advanced-features/ssr.mdx +4 -3
- package/docs/en/guides/advanced-features/web-server.mdx +1 -1
- package/docs/en/guides/concept/entries.mdx +130 -39
- package/docs/en/guides/get-started/introduction.mdx +1 -1
- package/docs/en/guides/get-started/quick-start.mdx +2 -0
- package/docs/en/guides/topic-detail/framework-plugin/hook-list.mdx +7 -3
- package/docs/en/guides/topic-detail/framework-plugin/plugin-api.mdx +29 -28
- package/docs/en/guides/topic-detail/generator/codesmith/api/fs.mdx +2 -2
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +4 -4
- package/docs/en/tutorials/first-app/c06-model.mdx +15 -12
- package/docs/en/tutorials/first-app/c07-container.mdx +22 -19
- package/docs/zh/apis/app/hooks/src/server.mdx +1 -28
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +1 -3
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +1 -4
- package/docs/zh/blog/index.md +71 -3
- package/docs/zh/blog/updates/2022-0708-updates.md +96 -0
- package/docs/zh/blog/updates/2022-0910-updates.md +80 -0
- package/docs/zh/blog/updates/_category_.json +5 -0
- package/docs/zh/blog/updates/v2-release-note.mdx +250 -0
- package/docs/zh/configure/app/output/splitRouteChunks.mdx +20 -0
- package/docs/zh/configure/app/source/config-dir.mdx +2 -2
- package/docs/zh/configure/app/source/design-system.mdx +3 -3
- package/docs/zh/configure/app/source/disable-default-entries.mdx +11 -10
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +2 -3
- package/docs/zh/configure/app/source/enable-async-entry.mdx +3 -3
- package/docs/zh/configure/app/source/entries-dir.mdx +10 -11
- package/docs/zh/configure/app/source/entries.mdx +84 -23
- package/docs/zh/configure/app/source/plugin-import.mdx +13 -0
- package/docs/zh/configure/app/source/transform-import.mdx +13 -0
- package/docs/zh/configure/app/tools/esbuild.mdx +9 -5
- package/docs/zh/configure/app/tools/jest.mdx +2 -3
- package/docs/zh/configure/app/tools/swc.mdx +6 -2
- package/docs/zh/guides/advanced-features/compatibility.mdx +1 -0
- package/docs/zh/guides/advanced-features/eslint.mdx +1 -1
- package/docs/zh/guides/advanced-features/rspack-start.mdx +1 -1
- package/docs/zh/guides/advanced-features/ssr.mdx +6 -3
- package/docs/zh/guides/advanced-features/web-server.mdx +10 -5
- package/docs/zh/guides/concept/entries.mdx +36 -35
- package/docs/zh/guides/get-started/quick-start.mdx +2 -0
- package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +6 -2
- package/docs/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +30 -29
- package/docs/zh/guides/topic-detail/generator/codesmith/api/fs.mdx +2 -2
- package/docs/zh/tutorials/first-app/c06-model.mdx +14 -12
- package/docs/zh/tutorials/first-app/c07-container.mdx +22 -19
- package/modern.config.ts +6 -7
- package/package.json +5 -5
- package/src/pages/index.tsx +10 -5
- package/en/configure/app/dev/asset-prefix.mdx +0 -13
- package/en/configure/app/dev/before-start-url.mdx +0 -13
- package/en/configure/app/dev/hmr.mdx +0 -13
- package/en/configure/app/dev/host.mdx +0 -13
- package/en/configure/app/dev/https.mdx +0 -13
- package/en/configure/app/dev/port.mdx +0 -13
- package/en/configure/app/dev/progress-bar.mdx +0 -13
- package/en/configure/app/dev/start-url.mdx +0 -13
- package/en/configure/app/experiments/lazy-compilation.mdx +0 -13
- package/en/configure/app/html/app-icon.mdx +0 -13
- package/en/configure/app/html/crossorigin.mdx +0 -13
- package/en/configure/app/html/disable-html-folder.mdx +0 -13
- package/en/configure/app/html/favicon-by-entries.mdx +0 -13
- package/en/configure/app/html/favicon.mdx +0 -13
- package/en/configure/app/html/inject-by-entries.mdx +0 -13
- package/en/configure/app/html/inject.mdx +0 -13
- package/en/configure/app/html/meta-by-entries.mdx +0 -13
- package/en/configure/app/html/meta.mdx +0 -13
- package/en/configure/app/html/mount-id.mdx +0 -13
- package/en/configure/app/html/tags-by-entries.mdx +0 -13
- package/en/configure/app/html/tags.mdx +0 -13
- package/en/configure/app/html/template-by-entries.mdx +0 -13
- package/en/configure/app/html/template-parameters-by-entries.mdx +0 -13
- package/en/configure/app/html/template-parameters.mdx +0 -13
- package/en/configure/app/html/template.mdx +0 -13
- package/en/configure/app/html/title-by-entries.mdx +0 -13
- package/en/configure/app/html/title.mdx +0 -13
- package/en/configure/app/output/asset-prefix.mdx +0 -13
- package/en/configure/app/output/assets-retry.mdx +0 -13
- package/en/configure/app/output/charset.mdx +0 -13
- package/en/configure/app/output/clean-dist-path.mdx +0 -13
- package/en/configure/app/output/convert-to-rem.mdx +0 -13
- package/en/configure/app/output/copy.mdx +0 -13
- package/en/configure/app/output/css-module-local-ident-name.mdx +0 -13
- package/en/configure/app/output/data-uri-limit.mdx +0 -13
- package/en/configure/app/output/disable-css-extract.mdx +0 -13
- package/en/configure/app/output/disable-css-module-extension.mdx +0 -13
- package/en/configure/app/output/disable-filename-hash.mdx +0 -13
- package/en/configure/app/output/disable-inline-runtime-chunk.mdx +0 -13
- package/en/configure/app/output/disable-minimize.mdx +0 -13
- package/en/configure/app/output/disable-source-map.mdx +0 -13
- package/en/configure/app/output/disable-ts-checker.mdx +0 -13
- package/en/configure/app/output/dist-path.mdx +0 -13
- package/en/configure/app/output/enable-asset-fallback.mdx +0 -13
- package/en/configure/app/output/enable-asset-manifest.mdx +0 -13
- package/en/configure/app/output/enable-css-module-tsdeclaration.mdx +0 -13
- package/en/configure/app/output/enable-inline-scripts.mdx +0 -13
- package/en/configure/app/output/enable-inline-styles.mdx +0 -13
- package/en/configure/app/output/enable-latest-decorators.mdx +0 -13
- package/en/configure/app/output/externals.mdx +0 -13
- package/en/configure/app/output/filename.mdx +0 -13
- package/en/configure/app/output/legal-comments.mdx +0 -13
- package/en/configure/app/output/override-browserslist.mdx +0 -13
- package/en/configure/app/output/polyfill.mdx +0 -13
- package/en/configure/app/output/svg-default-export.mdx +0 -13
- package/en/configure/app/performance/build-cache.mdx +0 -13
- package/en/configure/app/performance/bundle-analyze.mdx +0 -13
- package/en/configure/app/performance/chunk-split.mdx +0 -13
- package/en/configure/app/performance/print-file-size.mdx +0 -13
- package/en/configure/app/performance/profile.mdx +0 -13
- package/en/configure/app/performance/remove-console.mdx +0 -13
- package/en/configure/app/performance/remove-moment-locale.mdx +0 -13
- package/en/configure/app/security/check-syntax.mdx +0 -13
- package/en/configure/app/security/sri.mdx +0 -13
- package/en/configure/app/source/alias.mdx +0 -13
- package/en/configure/app/source/compile-js-data-uri.mdx +0 -13
- package/en/configure/app/source/define.mdx +0 -13
- package/en/configure/app/source/exclude.mdx +0 -13
- package/en/configure/app/source/global-vars.mdx +0 -13
- package/en/configure/app/source/include.mdx +0 -13
- package/en/configure/app/source/module-scopes.mdx +0 -13
- package/en/configure/app/source/pre-entry.mdx +0 -13
- package/en/configure/app/source/resolve-extension-prefix.mdx +0 -13
- package/en/configure/app/source/resolve-main-fields.mdx +0 -13
- package/en/configure/app/tools/autoprefixer.mdx +0 -13
- package/en/configure/app/tools/babel.mdx +0 -13
- package/en/configure/app/tools/css-extract.mdx +0 -13
- package/en/configure/app/tools/css-loader.mdx +0 -13
- package/en/configure/app/tools/dev-server.mdx +0 -13
- package/en/configure/app/tools/html-plugin.mdx +0 -13
- package/en/configure/app/tools/inspector.mdx +0 -13
- package/en/configure/app/tools/less.mdx +0 -13
- package/en/configure/app/tools/minify-css.mdx +0 -13
- package/en/configure/app/tools/postcss.mdx +0 -13
- package/en/configure/app/tools/pug.mdx +0 -13
- package/en/configure/app/tools/rspack.mdx +0 -13
- package/en/configure/app/tools/sass.mdx +0 -13
- package/en/configure/app/tools/style-loader.mdx +0 -13
- package/en/configure/app/tools/styled-components.mdx +0 -13
- package/en/configure/app/tools/terser.mdx +0 -13
- package/en/configure/app/tools/ts-checker.mdx +0 -13
- package/en/configure/app/tools/ts-loader.mdx +0 -13
- package/en/configure/app/tools/webpack-chain.mdx +0 -13
- package/en/configure/app/tools/webpack.mdx +0 -13
- package/zh/configure/app/dev/asset-prefix.mdx +0 -13
- package/zh/configure/app/dev/before-start-url.mdx +0 -13
- package/zh/configure/app/dev/hmr.mdx +0 -13
- package/zh/configure/app/dev/host.mdx +0 -13
- package/zh/configure/app/dev/https.mdx +0 -13
- package/zh/configure/app/dev/port.mdx +0 -13
- package/zh/configure/app/dev/progress-bar.mdx +0 -13
- package/zh/configure/app/dev/start-url.mdx +0 -13
- package/zh/configure/app/experiments/lazy-compilation.mdx +0 -13
- package/zh/configure/app/html/app-icon.mdx +0 -13
- package/zh/configure/app/html/crossorigin.mdx +0 -13
- package/zh/configure/app/html/disable-html-folder.mdx +0 -13
- package/zh/configure/app/html/favicon-by-entries.mdx +0 -13
- package/zh/configure/app/html/favicon.mdx +0 -13
- package/zh/configure/app/html/inject-by-entries.mdx +0 -13
- package/zh/configure/app/html/inject.mdx +0 -13
- package/zh/configure/app/html/meta-by-entries.mdx +0 -13
- package/zh/configure/app/html/meta.mdx +0 -13
- package/zh/configure/app/html/mount-id.mdx +0 -13
- package/zh/configure/app/html/tags-by-entries.mdx +0 -13
- package/zh/configure/app/html/tags.mdx +0 -13
- package/zh/configure/app/html/template-by-entries.mdx +0 -13
- package/zh/configure/app/html/template-parameters-by-entries.mdx +0 -13
- package/zh/configure/app/html/template-parameters.mdx +0 -13
- package/zh/configure/app/html/template.mdx +0 -13
- package/zh/configure/app/html/title-by-entries.mdx +0 -13
- package/zh/configure/app/html/title.mdx +0 -13
- package/zh/configure/app/output/asset-prefix.mdx +0 -13
- package/zh/configure/app/output/assets-retry.mdx +0 -13
- package/zh/configure/app/output/charset.mdx +0 -13
- package/zh/configure/app/output/clean-dist-path.mdx +0 -13
- package/zh/configure/app/output/convert-to-rem.mdx +0 -13
- package/zh/configure/app/output/copy.mdx +0 -13
- package/zh/configure/app/output/css-module-local-ident-name.mdx +0 -13
- package/zh/configure/app/output/data-uri-limit.mdx +0 -13
- package/zh/configure/app/output/disable-css-extract.mdx +0 -13
- package/zh/configure/app/output/disable-css-module-extension.mdx +0 -13
- package/zh/configure/app/output/disable-filename-hash.mdx +0 -13
- package/zh/configure/app/output/disable-inline-runtime-chunk.mdx +0 -13
- package/zh/configure/app/output/disable-minimize.mdx +0 -13
- package/zh/configure/app/output/disable-source-map.mdx +0 -13
- package/zh/configure/app/output/disable-ts-checker.mdx +0 -13
- package/zh/configure/app/output/dist-path.mdx +0 -13
- package/zh/configure/app/output/enable-asset-fallback.mdx +0 -13
- package/zh/configure/app/output/enable-asset-manifest.mdx +0 -13
- package/zh/configure/app/output/enable-css-module-tsdeclaration.mdx +0 -13
- package/zh/configure/app/output/enable-inline-scripts.mdx +0 -13
- package/zh/configure/app/output/enable-inline-styles.mdx +0 -13
- package/zh/configure/app/output/enable-latest-decorators.mdx +0 -13
- package/zh/configure/app/output/externals.mdx +0 -13
- package/zh/configure/app/output/filename.mdx +0 -13
- package/zh/configure/app/output/legal-comments.mdx +0 -13
- package/zh/configure/app/output/override-browserslist.mdx +0 -13
- package/zh/configure/app/output/polyfill.mdx +0 -13
- package/zh/configure/app/output/svg-default-export.mdx +0 -13
- package/zh/configure/app/performance/build-cache.mdx +0 -13
- package/zh/configure/app/performance/bundle-analyze.mdx +0 -13
- package/zh/configure/app/performance/chunk-split.mdx +0 -13
- package/zh/configure/app/performance/print-file-size.mdx +0 -13
- package/zh/configure/app/performance/profile.mdx +0 -13
- package/zh/configure/app/performance/remove-console.mdx +0 -13
- package/zh/configure/app/performance/remove-moment-locale.mdx +0 -13
- package/zh/configure/app/security/check-syntax.mdx +0 -13
- package/zh/configure/app/security/sri.mdx +0 -13
- package/zh/configure/app/source/alias.mdx +0 -13
- package/zh/configure/app/source/compile-js-data-uri.mdx +0 -13
- package/zh/configure/app/source/define.mdx +0 -13
- package/zh/configure/app/source/exclude.mdx +0 -13
- package/zh/configure/app/source/global-vars.mdx +0 -13
- package/zh/configure/app/source/include.mdx +0 -13
- package/zh/configure/app/source/module-scopes.mdx +0 -13
- package/zh/configure/app/source/pre-entry.mdx +0 -13
- package/zh/configure/app/source/resolve-extension-prefix.mdx +0 -13
- package/zh/configure/app/source/resolve-main-fields.mdx +0 -13
- package/zh/configure/app/tools/autoprefixer.mdx +0 -13
- package/zh/configure/app/tools/babel.mdx +0 -13
- package/zh/configure/app/tools/css-extract.mdx +0 -13
- package/zh/configure/app/tools/css-loader.mdx +0 -13
- package/zh/configure/app/tools/dev-server.mdx +0 -13
- package/zh/configure/app/tools/html-plugin.mdx +0 -13
- package/zh/configure/app/tools/inspector.mdx +0 -13
- package/zh/configure/app/tools/less.mdx +0 -13
- package/zh/configure/app/tools/minify-css.mdx +0 -13
- package/zh/configure/app/tools/postcss.mdx +0 -13
- package/zh/configure/app/tools/pug.mdx +0 -13
- package/zh/configure/app/tools/rspack.mdx +0 -13
- package/zh/configure/app/tools/sass.mdx +0 -13
- package/zh/configure/app/tools/style-loader.mdx +0 -13
- package/zh/configure/app/tools/styled-components.mdx +0 -13
- package/zh/configure/app/tools/terser.mdx +0 -13
- package/zh/configure/app/tools/ts-checker.mdx +0 -13
- package/zh/configure/app/tools/ts-loader.mdx +0 -13
- package/zh/configure/app/tools/webpack-chain.mdx +0 -13
- package/zh/configure/app/tools/webpack.mdx +0 -13
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
+
## 2.11.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- a8c08c3: feat: 添加 `source.transformImoprt`
|
8
|
+
|
9
|
+
feat: add `source.transformImoprt`
|
10
|
+
|
11
|
+
- 304c950: fix: translate some chinese to english in en docs
|
12
|
+
fix: 将部分英文文档中的中文翻译为英文
|
13
|
+
- Updated dependencies [a8c08c3]
|
14
|
+
- Updated dependencies [b71cef1]
|
15
|
+
- @modern-js/builder-doc@2.11.0
|
16
|
+
|
17
|
+
## 2.10.0
|
18
|
+
|
19
|
+
### Patch Changes
|
20
|
+
|
21
|
+
- 92d247f: fix: support tools.devServer.header include string[] type, remove get & delete & apply api in hook or middleware api
|
22
|
+
fix: 支持 tools.devServer.header 包含字符串数组类型,移除 Hook 和 Middleware 中对 响应 Cookie 的获取、删除操作
|
23
|
+
- 19e552a: fix: main doc theme
|
24
|
+
|
25
|
+
fix: 首页深色模式问题
|
26
|
+
|
27
|
+
- Updated dependencies [cfdbf80]
|
28
|
+
- @modern-js/builder-doc@2.10.0
|
29
|
+
|
3
30
|
## 2.9.0
|
4
31
|
|
5
32
|
### Patch Changes
|
@@ -4,31 +4,4 @@ sidebar_position: 8
|
|
4
4
|
---
|
5
5
|
# *.[server|node].[tj]sx
|
6
6
|
|
7
|
-
Used in application projects to place server side code,
|
8
|
-
|
9
|
-
1. When `*.tsx` and `*. [server|node].tsx` coexist, rendering on the server side will give preference to the `*. [server|node].tsx` file instead of the `*.tsx` file.
|
10
|
-
|
11
|
-
2. When using [data loader](/guides/basic-features/data-fetch), the server-side dependencies need to be re-exported from this file
|
12
|
-
|
13
|
-
```tsx
|
14
|
-
// routes/user/avatar.tsx
|
15
|
-
import { useLoaderData } from '@modern-js/runtime/router';
|
16
|
-
import { readFile } from './utils.server';
|
17
|
-
|
18
|
-
type ProfileData = {
|
19
|
-
/* some type declarations */
|
20
|
-
};
|
21
|
-
|
22
|
-
export const loader = async (): ProfileData => {
|
23
|
-
const profile = await readFile('profile.json');
|
24
|
-
return profile;
|
25
|
-
};
|
26
|
-
|
27
|
-
export default function UserPage() {
|
28
|
-
const profileData = useLoaderData() as ProfileData;
|
29
|
-
return <div>{profileData}</div>;
|
30
|
-
}
|
31
|
-
|
32
|
-
// routes/user/utils.server.ts
|
33
|
-
export * from 'fs-extra';
|
34
|
-
```
|
7
|
+
Used in application projects to place server side code, When `*.tsx` and `*. [server|node].tsx` coexist, rendering on the server side will give preference to the `*. [server|node].tsx` file instead of the `*.tsx` file.
|
@@ -38,9 +38,7 @@ type HookContext = {
|
|
38
38
|
set: (key: string, value: string) => void;
|
39
39
|
status: (code: number) => void;
|
40
40
|
cookies: {
|
41
|
-
|
42
|
-
set: (key: string, value: string) => void;
|
43
|
-
delete: () => void;
|
41
|
+
set: (key: string, value: string, options?: any) => void;
|
44
42
|
clear: () => void;
|
45
43
|
};
|
46
44
|
raw: (
|
@@ -46,11 +46,8 @@ type MiddlewareContext = {
|
|
46
46
|
set: (key: string, value: string) => void;
|
47
47
|
status: (code: number) => void;
|
48
48
|
cookies: {
|
49
|
-
|
50
|
-
set: (key: string, value: string) => void;
|
51
|
-
delete: () => void;
|
49
|
+
set: (key: string, value: string, options?: any) => void;
|
52
50
|
clear: () => void;
|
53
|
-
apply: () => void;
|
54
51
|
};
|
55
52
|
raw: (
|
56
53
|
body: string,
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: splitRouteChunks
|
3
|
+
---
|
4
|
+
|
5
|
+
# output.splitRouteChunks
|
6
|
+
|
7
|
+
- **Type:** `boolean`
|
8
|
+
- **Default:** `true`
|
9
|
+
|
10
|
+
When using convention-based routing, the framework will split js and css based on the route to load on demand. If your project does not want to split js and css based on routes, you can set this option to `false`.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
|
14
|
+
```ts
|
15
|
+
export default {
|
16
|
+
output: {
|
17
|
+
splitRouteChunks: false,
|
18
|
+
},
|
19
|
+
}
|
20
|
+
```
|
@@ -1,26 +1,19 @@
|
|
1
1
|
---
|
2
|
-
title: source.disableDefaultEntries
|
3
2
|
sidebar_label: disableDefaultEntries
|
4
3
|
---
|
5
|
-
|
4
|
+
|
5
|
+
# source.disableDefaultEntries
|
6
6
|
|
7
7
|
- **Type:** `boolean`
|
8
8
|
- **Default:** `false`
|
9
9
|
|
10
|
-
|
10
|
+
Used to disable the function of automatically identifying the page entry according to the project directory structure.
|
11
11
|
|
12
12
|
:::info
|
13
|
-
By default, Modern.js will get the
|
14
|
-
After configuring the shutdown mechanism, you need to configure the custom entry with [`source.entries`](/configure/app/source/entries).
|
15
|
-
|
16
|
-
:::
|
17
|
-
|
18
|
-
:::warning Warning
|
19
|
-
Organizing your code according to the catalog specification provided by the Modern.js is recommended to make better use of the framework's capabilities and avoid some redundant configuration.
|
20
|
-
|
13
|
+
By default, Modern.js will get the page entries according to the project directory structure. For details, please refer to [Entry](/guides/concept/entries).
|
21
14
|
:::
|
22
15
|
|
23
|
-
Set the following to
|
16
|
+
Set the following to disable the default behavior:
|
24
17
|
|
25
18
|
```ts title="modern.config.ts"
|
26
19
|
export default defineConfig({
|
@@ -29,3 +22,10 @@ export default defineConfig({
|
|
29
22
|
},
|
30
23
|
});
|
31
24
|
```
|
25
|
+
|
26
|
+
After turning off the default behavior, you need to use [`source.entries`](/configure/app/source/entries) to configure custom entries.
|
27
|
+
|
28
|
+
:::warning
|
29
|
+
We recommend using the directory convention provided by Modern.js to organize the code, so as to better use the functions of the framework and avoid some redundant configurations.
|
30
|
+
|
31
|
+
:::
|
@@ -1,14 +1,13 @@
|
|
1
1
|
---
|
2
|
-
title: source.disableEntryDirs
|
3
|
-
|
4
2
|
sidebar_label: disableEntryDirs
|
5
3
|
---
|
6
|
-
|
4
|
+
|
5
|
+
# source.disableEntryDirs
|
7
6
|
|
8
7
|
- **Type:** `string[]`
|
9
8
|
- **Default:** `[]`
|
10
9
|
|
11
|
-
By default, application entries are identified based on the
|
10
|
+
By default, application entries are identified based on the `src` directory, you can disable some directories from being identified as application entries with this option.
|
12
11
|
|
13
12
|
For example, when the configuration and directory structure is as follows:
|
14
13
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
---
|
2
|
-
title: source.entriesDir
|
3
2
|
sidebar_label: entriesDir
|
4
3
|
---
|
5
|
-
|
4
|
+
|
5
|
+
# source.entriesDir
|
6
6
|
|
7
7
|
- **Type:** `string`
|
8
8
|
- **Default:** `./src`
|
9
9
|
|
10
|
-
|
10
|
+
Modern.js will scan the `src` directory by default to identify the page entries, you can customize the identification directory of the page entries through this option.
|
11
11
|
|
12
12
|
For example, when the configuration and directory structure are as follows:
|
13
13
|
|
@@ -24,16 +24,16 @@ export default defineConfig({
|
|
24
24
|
└── src
|
25
25
|
└── pages
|
26
26
|
├── a
|
27
|
-
│ └── App.
|
27
|
+
│ └── App.tsx
|
28
28
|
└── b
|
29
|
-
└── App.
|
29
|
+
└── App.tsx
|
30
30
|
```
|
31
31
|
|
32
|
-
Modern.js will generate the build entry `a` and
|
32
|
+
Modern.js will generate the build entry `a` and `b` according to the `./src/pages` directory structure, the result is as follows:
|
33
33
|
|
34
34
|
```js
|
35
|
-
{
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
const entry = {
|
36
|
+
a: './src/pages/a/App.tsx',
|
37
|
+
b: './src/pages/b/App.tsx',
|
38
|
+
};
|
39
39
|
```
|
@@ -1,19 +1,36 @@
|
|
1
1
|
---
|
2
|
-
title: source.entries
|
3
2
|
sidebar_label: entries
|
4
3
|
---
|
5
|
-
# entries
|
6
4
|
|
7
|
-
|
8
|
-
- **Default:** Default entry object dynamically settled according to the current project directory structure.
|
5
|
+
# source.entries
|
9
6
|
|
10
|
-
|
7
|
+
- **Type:**
|
11
8
|
|
12
|
-
|
9
|
+
```ts
|
10
|
+
type Entries = Record<
|
11
|
+
string,
|
12
|
+
| string
|
13
|
+
| {
|
14
|
+
entry: string;
|
15
|
+
disableMount?: boolean;
|
16
|
+
}
|
17
|
+
>;
|
18
|
+
```
|
19
|
+
|
20
|
+
- **Default:** An entry object calculated from the directory structure of the current project.
|
21
|
+
|
22
|
+
Used to configure custom page entries.
|
23
|
+
|
24
|
+
:::tip When to use
|
25
|
+
For most scenarios, the entries automatically generated by Modern.js according to the directory structure can already meet the requirements. For details, please refer to [entries](/guides/concept/entries).
|
26
|
+
|
27
|
+
If you need to customize the page entry, you can set it through this option.
|
28
|
+
|
29
|
+
:::
|
13
30
|
|
14
31
|
## String
|
15
32
|
|
16
|
-
When the value
|
33
|
+
When the value of `entries` object is `string` type, it means the file path of the entry module:
|
17
34
|
|
18
35
|
```ts title="modern.config.ts"
|
19
36
|
import { defineConfig } from '@modern-js/app-tools';
|
@@ -22,13 +39,14 @@ export default defineConfig({
|
|
22
39
|
source: {
|
23
40
|
entries: {
|
24
41
|
// Specify a new entry named entry_customize
|
25
|
-
entry_customize: './src/home/test/index.
|
42
|
+
entry_customize: './src/home/test/index.ts',
|
26
43
|
},
|
44
|
+
disableDefaultEntries: true,
|
27
45
|
},
|
28
46
|
});
|
29
47
|
```
|
30
48
|
|
31
|
-
By default, the configured entry is equivalent to `App.[jt]sx`, that is, the specified entry file only needs to export the root component of the application
|
49
|
+
By default, the configured entry is equivalent to `App.[jt]sx`, that is, the specified entry file **only needs to export the root component of the application**.
|
32
50
|
|
33
51
|
For example the following directory structure:
|
34
52
|
|
@@ -41,17 +59,18 @@ For example the following directory structure:
|
|
41
59
|
└── package.json
|
42
60
|
```
|
43
61
|
|
44
|
-
|
62
|
+
The above directory does not conform to the directory structure convention of Modern.js, therefore, Modern.js will not get any default entry when analyzing the directory structure.
|
45
63
|
|
46
64
|
In cases where you do not want to change the directory structure (such as project migration), you can customize the entry through `source.entries`:
|
47
65
|
|
48
|
-
```ts title="modern.config.
|
66
|
+
```ts title="modern.config.ts"
|
49
67
|
export default defineConfig({
|
50
68
|
source: {
|
51
69
|
entries: {
|
52
70
|
home: './src/entry/home.tsx',
|
53
71
|
chat: './src/entry/chat.tsx',
|
54
72
|
},
|
73
|
+
disableDefaultEntries: true,
|
55
74
|
},
|
56
75
|
});
|
57
76
|
```
|
@@ -60,8 +79,8 @@ export default defineConfig({
|
|
60
79
|
|
61
80
|
When the value is `Object`, the following properties can be configured:
|
62
81
|
|
63
|
-
- `entry`: `string
|
64
|
-
- `disableMount`: `boolean = false
|
82
|
+
- `entry`: `string`, entry file path.
|
83
|
+
- `disableMount`: `boolean = false`, turn off the entry-scanning behavior of Modern.js.
|
65
84
|
|
66
85
|
```ts title="modern.config.ts"
|
67
86
|
import { defineConfig } from '@modern-js/app-tools';
|
@@ -71,25 +90,63 @@ export default defineConfig({
|
|
71
90
|
entries: {
|
72
91
|
entry_customize: {
|
73
92
|
// entry file path
|
74
|
-
entry: './src/home/test/App.
|
93
|
+
entry: './src/home/test/App.tsx',
|
94
|
+
},
|
95
|
+
},
|
96
|
+
disableDefaultEntries: true,
|
97
|
+
},
|
98
|
+
});
|
99
|
+
```
|
100
|
+
|
101
|
+
### Disable entry file generation
|
102
|
+
|
103
|
+
By default, the configured entry is equivalent to `App.[jt]sx`, and Modern.js will automatically generate an entry file to reference your configured entry.
|
104
|
+
|
105
|
+
If you want to disable the logic of Modern.js automatically generating the entry file, you can set the `disableMount` property to `true`.
|
106
|
+
|
107
|
+
```ts title="modern.config.ts"
|
108
|
+
export default defineConfig({
|
109
|
+
source: {
|
110
|
+
entries: {
|
111
|
+
entry_customize: {
|
112
|
+
entry: './src/home/test/index.tsx',
|
113
|
+
disableMount: true,
|
75
114
|
},
|
76
|
-
|
115
|
+
},
|
116
|
+
// Disable default ingress scanning
|
117
|
+
disableDefaultEntries: true,
|
118
|
+
},
|
119
|
+
});
|
120
|
+
```
|
121
|
+
|
122
|
+
### Conventional Routing
|
123
|
+
|
124
|
+
If you need to enable conventional routing for a custom entry, you can set `entry` to a directory path:
|
125
|
+
|
126
|
+
```ts title="modern.config.ts"
|
127
|
+
import { defineConfig } from '@modern-js/app-tools';
|
128
|
+
|
129
|
+
export default defineConfig({
|
130
|
+
source: {
|
131
|
+
entries: {
|
132
|
+
// enable conventional routing
|
77
133
|
entry_spa: {
|
78
|
-
// The entry path of
|
134
|
+
// The entry path of conventional routing must be set to a directory
|
79
135
|
entry: './src/about',
|
80
136
|
},
|
81
137
|
},
|
138
|
+
disableDefaultEntries: true,
|
82
139
|
},
|
83
140
|
});
|
84
141
|
```
|
85
142
|
|
86
|
-
|
143
|
+
## Entry Merge Rules
|
87
144
|
|
88
|
-
|
145
|
+
After setting `source.entries`, if `disableDefaultEntries: true` is not set, Modern.js will merge the custom entry with the entry obtained by analyzing the directory structure.
|
89
146
|
|
90
|
-
|
147
|
+
The merge rule is:
|
91
148
|
|
92
|
-
Compare the entry path set by the custom entry with the default entry path. When the entry
|
149
|
+
- Compare the entry path set by the custom entry with the default entry path. When the entry path is consistent, the custom entry will override the default entry.
|
93
150
|
|
94
151
|
For example the following directory structure:
|
95
152
|
|
@@ -97,13 +154,13 @@ For example the following directory structure:
|
|
97
154
|
.
|
98
155
|
├── src
|
99
156
|
│ ├── chat
|
100
|
-
│ │ └── App.
|
157
|
+
│ │ └── App.tsx
|
101
158
|
│ └── home
|
102
|
-
│ └── index.
|
159
|
+
│ └── index.ts
|
103
160
|
└── package.json
|
104
161
|
```
|
105
162
|
|
106
|
-
Modern.js analyze the `src/` directory to get the default entries `chat` and `home`. When the user configures the following in the `modern.config.
|
163
|
+
Modern.js will analyze the `src/` directory to get the default entries `chat` and `home`. When the user configures the following in the `modern.config.ts` file:
|
107
164
|
|
108
165
|
```ts title="modern.config.ts"
|
109
166
|
import { defineConfig } from '@modern-js/app-tools';
|
@@ -111,7 +168,7 @@ import { defineConfig } from '@modern-js/app-tools';
|
|
111
168
|
export default defineConfig({
|
112
169
|
source: {
|
113
170
|
entries: {
|
114
|
-
index: './src/home/index.
|
171
|
+
index: './src/home/index.ts',
|
115
172
|
},
|
116
173
|
},
|
117
174
|
};
|
@@ -119,5 +176,5 @@ export default defineConfig({
|
|
119
176
|
|
120
177
|
You can see that the path of the custom entry `index` is the same as the path of the default entry `home`. During the merging process, `index` will override `home`, and the final entry is as follows:
|
121
178
|
|
122
|
-
- `chat -> ./src/chat/App.
|
123
|
-
- `index -> ./src/home/index.
|
179
|
+
- `chat -> ./src/chat/App.tsx`
|
180
|
+
- `index -> ./src/home/index.ts`
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: pluginImport
|
3
|
+
---
|
4
|
+
|
5
|
+
# source.transformImport
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
This config is provided by Modern.js Builder, more detail can see [source.transformImport](https://modernjs.dev/builder/en/api/config-source.html#sourcepluginimport).
|
9
|
+
:::
|
10
|
+
|
11
|
+
import Main from '@modern-js/builder-doc/docs/en/config/source/transformImport.md';
|
12
|
+
|
13
|
+
<Main />
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: transformImport
|
3
|
+
---
|
4
|
+
|
5
|
+
# source.transformImport
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
This config is provided by Modern.js Builder, more detail can see [source.transformImport](https://modernjs.dev/builder/en/api/config-source.html#sourcetransformimport).
|
9
|
+
:::
|
10
|
+
|
11
|
+
import Main from '@modern-js/builder-doc/docs/en/config/source/transformImport.md';
|
12
|
+
|
13
|
+
<Main />
|
@@ -1,20 +1,25 @@
|
|
1
1
|
---
|
2
|
-
title: tools.esbuild
|
3
2
|
sidebar_label: esbuild
|
4
3
|
---
|
5
|
-
|
4
|
+
|
5
|
+
# tools.esbuild
|
6
6
|
|
7
7
|
- **Type:** `Object`
|
8
8
|
- **Default:** `undefined`
|
9
9
|
|
10
10
|
## Introduction
|
11
11
|
|
12
|
-
:::tip About esbuild
|
13
12
|
[esbuild](https://esbuild.github.io/) is a front-end build tool based on Golang. It has the functions of bundling, compiling and minimizing JavaScript code. Compared with traditional tools, the performance is significantly improved. When minimizing code, compared to webpack's built-in terser minimizer, esbuild has dozens of times better performance.
|
14
13
|
|
14
|
+
Modern.js provides esbuild plugin that allow you to use esbuild instead of babel-loader, ts-loader and terser for transformation and minification process.
|
15
|
+
|
16
|
+
:::tip Recommend using SWC
|
17
|
+
We recommend using SWC to transform and minify code rather than esbuild, because SWC supports more syntaxes, provides better code compression, and the compiled code has better compatibility.
|
18
|
+
|
19
|
+
Therefore, we recommend that you use SWC instead of esbuild, please refer to [tools.swc](/configure/app/tools/swc) for usage.
|
20
|
+
|
15
21
|
:::
|
16
22
|
|
17
|
-
Modern.js provides esbuild plugin that allow you to use esbuild instead of babel-loader, ts-loader and terser for transformation and minification process.
|
18
23
|
|
19
24
|
## Configuration
|
20
25
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
---
|
2
|
-
title: tools.swc
|
3
2
|
sidebar_label: swc
|
4
3
|
---
|
5
|
-
|
4
|
+
|
5
|
+
# tools.swc
|
6
6
|
|
7
7
|
- **Type:** `Object`
|
8
8
|
- **Default:** `undefined`
|
@@ -13,6 +13,10 @@ sidebar_label: swc
|
|
13
13
|
|
14
14
|
Modern.js Builder has a out-of-box plugin for SWC, power your Web application with Polyfill and minification, we also port some common used Babel plugins to SWC.
|
15
15
|
|
16
|
+
:::tip
|
17
|
+
When using Rspack as the bundler, SWC will be used for transpiling and compression by default, so you don't need to install or configure the SWC plugin.
|
18
|
+
:::
|
19
|
+
|
16
20
|
## Install
|
17
21
|
|
18
22
|
The `@modern-js/plugin-swc` plugin needs to be installed before use.
|
@@ -75,4 +75,5 @@ Visit the page `http://localhost:8080/__polyfill__` on Chrome 51 to see:
|
|
75
75
|
:::caution
|
76
76
|
This feature only works when using Modern.js built-in Web Server.
|
77
77
|
|
78
|
+
If you need to customize the HTML template, please refer to [HTML Template](/guides/basic-features/html.html). Manually modifying the template through html.template / tools.html will cause this feature not work.
|
78
79
|
:::
|
@@ -22,8 +22,8 @@ export default defineConfig({
|
|
22
22
|
|
23
23
|
Modern.js provides Data Loader, which is convenient for developers to fetch data under SSR and CSR. Each routing module, such as `layout.tsx` and `page.tsx`, can define its own Data Loader:
|
24
24
|
|
25
|
-
```ts title="src/routes/page.
|
26
|
-
export
|
25
|
+
```ts title="src/routes/page.loader.ts"
|
26
|
+
export default () => {
|
27
27
|
return {
|
28
28
|
message: 'Hello World',
|
29
29
|
};
|
@@ -49,6 +49,7 @@ However, developers still need to pay attention to the fallback of data, such as
|
|
49
49
|
1. When you request the page on client-side page transitions, Modern.js sends an API request to the server, which runs Data Loader function.
|
50
50
|
|
51
51
|
2. When using Data Loader, data fetching happens before rendering, Modern.js still supports fetching data when the component is rendered. See [Data Fetch](/guides/basic-features/data-fetch).
|
52
|
+
|
52
53
|
:::
|
53
54
|
|
54
55
|
## Keep Rendering Consistent
|
@@ -225,7 +226,7 @@ The Node API is introduced in the component file, usually because of the use of
|
|
225
226
|
|
226
227
|
```ts
|
227
228
|
import fse from 'fs-extra';
|
228
|
-
export
|
229
|
+
export default () => {
|
229
230
|
const file = fse.readFileSync('./myfile');
|
230
231
|
return {
|
231
232
|
...
|
@@ -80,7 +80,7 @@ Modern.js provides a set of APIs by default for projects to use:
|
|
80
80
|
```ts
|
81
81
|
import { Middlewre } from '@modern-js/runtime/server';
|
82
82
|
|
83
|
-
export const middleware = (context, next) => {
|
83
|
+
export const middleware: Middlewre = (context, next) => {
|
84
84
|
const { source: { req, res } } = context;
|
85
85
|
console.log(req.url);
|
86
86
|
next();
|