@modern-js/module-tools-docs 2.57.0 → 2.58.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @modern-js/module-tools-docs
2
2
 
3
+ ## 2.58.0
4
+
5
+ ## 2.57.1
6
+
3
7
  ## 2.57.0
4
8
 
5
9
  ## 2.56.2
@@ -753,7 +753,8 @@ Build lifecycle hooks that allow custom logic to be injected at specific stages
753
753
  ```ts
754
754
  type HookList = {
755
755
  name: string;
756
- apply: (compiler: ICompiler) => void.
756
+ apply: (compiler: ICompiler) => void;
757
+ applyAfterBuiltIn?: boolean;
757
758
  }
758
759
 
759
760
  ```
@@ -878,8 +879,27 @@ For more information about JSX Transform, you can refer to the following links:
878
879
 
879
880
  - [React Blog - Introducing the New JSX Transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html).
880
881
  - [esbuild - JSX](https://esbuild.github.io/api/#jsx).
882
+
881
883
  :::
882
884
 
885
+
886
+ ## loader
887
+
888
+ **Experimental**
889
+
890
+ This option is used to change the interpretation method of the given input file.
891
+ For example, you need to handle the js file as jsx.
892
+
893
+ ```js title="modern.config.ts"
894
+ export default defineConfig({
895
+ buildConfig: {
896
+ loader: {
897
+ '.js': 'jsx',
898
+ }
899
+ },
900
+ });
901
+ ```
902
+
883
903
  ## metafile
884
904
 
885
905
  This option is used for build analysis. When enabled, esbuild will generate metadata about the build in JSON format.
@@ -978,6 +998,34 @@ export default {
978
998
 
979
999
  Custom module resolution options
980
1000
 
1001
+ ### resolve.alias
1002
+
1003
+ The basic usage is the same as [alias](#alias).
1004
+
1005
+ The issue with [alias](#alias) is that we incorrectly handled Module IDs in a bundleless scenario:
1006
+ ```js
1007
+ import { createElement } from "react";
1008
+ ```
1009
+ When we configure alias: `{ react: 'react-native' }`, the result becomes:
1010
+ ```js
1011
+ import { createElement } from "./react-native";
1012
+ ```
1013
+ A Module ID is incorrectly processed as a relative path, which is not expected.
1014
+
1015
+ We want to fix this issue, but it may break existing projects.
1016
+
1017
+ Therefore, in **MAJOR_VERSION.58.0**, we provided `resolve.alias` to solve this problem. Additionally, `resolve.alias` removed the default value `{ "@": "./src"}` provided by [alias](#alias).
1018
+
1019
+ If you need this feature, please use `resolve.alias`.
1020
+
1021
+ In the next major version, `resolve.alias` will replace [alias](#alias).
1022
+
1023
+ :::warning
1024
+ - Note that this configuration should not be mixed with [alias](#alias).
1025
+ - Ensure that this configuration specifies a relative path, such as `{ "@": "./src" }` rather than `{ "@": "src"}`.
1026
+
1027
+ :::
1028
+
981
1029
  ### resolve.mainFields
982
1030
 
983
1031
  A list of fields in package.json to try when parsing the package entry point.
@@ -95,6 +95,10 @@ Serial hooks that stop the execution of other tapped functions if a tapped funct
95
95
 
96
96
  Serial hooks whose results are passed to the next tapped function.
97
97
 
98
+ ### Hook Order
99
+
100
+ The execution order of hooks follows the registration order. You can control whether a hook is registered before or after the built-in hooks using `applyAfterBuiltIn`.
101
+
98
102
  ### Hook API
99
103
 
100
104
  #### load
@@ -9,5 +9,5 @@ Modern.js Module uses esbuild to build toolkits and component libraries, and Rsb
9
9
  Modern.js Module is based on esbuild for building and cannot use tools from the webpack-related ecosystem.
10
10
  You can find more community plugins for esbuild [here](https://github.com/esbuild/community-plugins)
11
11
 
12
- If the UMD product produced by Modern.js Module does not meet your requirements, you can use Rsbuild and add [UMD Plugin](https://rsbuild.dev/plugins/list/plugin-umd) to build UMD products.
12
+ If the UMD product produced by Modern.js Module does not meet your requirements, you can use Rsbuild and add [UMD Plugin](https://github.com/rspack-contrib/rsbuild-plugin-umd) to build UMD products.
13
13
 
@@ -744,6 +744,8 @@ export default defineConfig({
744
744
  type HookList = {
745
745
  name: string;
746
746
  apply: (compiler: ICompiler) => void;
747
+ // 是否在 buildIn 钩子之后执行
748
+ applyAfterBuiltIn?: boolean;
747
749
  };
748
750
  ```
749
751
 
@@ -870,6 +872,22 @@ export default defineConfig({
870
872
 
871
873
  :::
872
874
 
875
+ ## loader
876
+
877
+ **试验性功能**
878
+
879
+ 此选项用来更改给定输入文件的解释方式。例如你需要将 js 文件当做 jsx 处理
880
+
881
+ ```js title="modern.config.ts"
882
+ export default defineConfig({
883
+ buildConfig: {
884
+ loader: {
885
+ '.js': 'jsx',
886
+ }
887
+ },
888
+ });
889
+ ```
890
+
873
891
  ## metafile
874
892
 
875
893
  这个选项用于构建分析,开启该选项后,esbuild 会以 JSON 格式生成有关构建的一些元数据。
@@ -968,6 +986,33 @@ export default {
968
986
 
969
987
  自定义模块解析选项
970
988
 
989
+ ### resolve.alias
990
+
991
+ 基本用法和 [alias](#alias) 一致。
992
+
993
+ [alias](#alias) 的问题在于我们在 bundleless 场景下错误的处理了 Module ID 的情况:
994
+ ```js
995
+ import { createElement } from "react";
996
+ ```
997
+ 当我们配置了 `alias: { react: 'react-native' }` 后,结果会变成
998
+ ```js
999
+ import { createElement } from "./react-native";
1000
+ ```
1001
+ 一个 Module ID 被错误的处理成了相对路径,显然这是不符合预期的。
1002
+
1003
+ 我们想要修复这个问题,但是这可能会破坏已有的项目,因此我们在 MAJOR_VERSION.58.0 版本提供了 `resolve.alias` 来解决这个问题。
1004
+ 并且 `resolve.alias` 里移除了 [alias](#alias) 提供的默认值 `{ "@": "./src"}`
1005
+
1006
+ 如果你需要此功能,请使用 `resolve.alias`。
1007
+
1008
+ 在下一个大版本,`resolve.alias` 将会取代 `alias` 。
1009
+
1010
+ :::warning
1011
+ - 注意此配置不要与 [alias](#alias) 混用。
1012
+ - 注意此配置必须标注一个相对路径,例如 `{ "@": "./src" }` 而非 `{ "@": "src"}`。
1013
+
1014
+ :::
1015
+
971
1016
  ### resolve.mainFields
972
1017
 
973
1018
  package.json 中,在解析包的入口点时尝试的字段列表。
@@ -1595,4 +1640,6 @@ export default defineConfig({
1595
1640
  },
1596
1641
  },
1597
1642
  });
1598
- ```
1643
+ ```import { aliases } from '../../../../../../toolkit/utils/dist/compiled/browserslist';
1644
+ import { createElement } from 'react';
1645
+
@@ -95,6 +95,10 @@ Modern.js Module Hook 使用了 [tapable](https://github.com/webpack/tapable)
95
95
 
96
96
  串行执行的 hooks,其结果会传递给下一个 tapped function
97
97
 
98
+ ### Hook 顺序
99
+
100
+ Hook 的执行顺序和注册顺序保持一致,可以通过 `applyAfterBuiltIn` 来控制在 BuiltIn Hook 前或后注册。
101
+
98
102
  ### Hook API
99
103
 
100
104
  #### load
@@ -9,4 +9,4 @@ Modern.js Module 使用 esbuild 构建工具库和组件库,Rsbuild 专注于
9
9
  Modern.js Module 基于 esbuild 构建,无法使用 webpack 相关生态的工具。
10
10
  [这里](https://github.com/esbuild/community-plugins)可以发现更多 esbuild 社区插件
11
11
 
12
- 如果 Modern.js Module 生产的 UMD 产物达不到你的要求,可以使用 Rsbuild 并添加 [UMD Plugin](https://rsbuild.dev/zh/plugins/list/plugin-umd) 构建 UMD 产物。
12
+ 如果 Modern.js Module 生产的 UMD 产物达不到你的要求,可以使用 Rsbuild 并添加 [UMD Plugin](https://github.com/rspack-contrib/rsbuild-plugin-umd) 构建 UMD 产物。
package/package.json CHANGED
@@ -9,14 +9,14 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.57.0",
12
+ "version": "2.58.0",
13
13
  "main": "index.js",
14
14
  "devDependencies": {
15
15
  "react": "^18.2.0",
16
16
  "react-dom": "^18.2.0",
17
17
  "rspress": "1.26.1",
18
18
  "@rspress/shared": "1.26.1",
19
- "@modern-js/doc-plugin-auto-sidebar": "2.57.0"
19
+ "@modern-js/doc-plugin-auto-sidebar": "2.58.0"
20
20
  },
21
21
  "scripts": {
22
22
  "dev": "rspress dev",