@modern-js/module-tools-docs 2.31.2 → 2.32.1

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,24 @@
1
1
  # @modern-js/module-tools-docs
2
2
 
3
+ ## 2.32.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @modern-js/doc-plugin-auto-sidebar@2.32.1
8
+ - @modern-js/doc-tools@2.32.1
9
+
10
+ ## 2.32.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 8d22b87: docs: add content about transformLodash and fix a error about english content
15
+ docs: 添加关于 transformLodash 的内容,并且修复一个英文内容的错误
16
+
17
+ ### Patch Changes
18
+
19
+ - @modern-js/doc-plugin-auto-sidebar@2.32.0
20
+ - @modern-js/doc-tools@2.32.0
21
+
3
22
  ## 2.31.2
4
23
 
5
24
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Modern.js
3
+ Copyright (c) 2021-present Modern.js
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1036,6 +1036,8 @@ After enabling `inject`, you need to pay attention to the following points:
1036
1036
 
1037
1037
  You can resolve this by configuring [sideEffects](#sideeffects).
1038
1038
 
1039
+ :::
1040
+
1039
1041
  ## style.autoModules
1040
1042
 
1041
1043
  Enable CSS Modules automatically based on the filename.
@@ -1095,13 +1097,8 @@ tailwindcss related configuration
1095
1097
  ```js title="modern.config.ts"
1096
1098
  const tailwind = {
1097
1099
  content: [
1098
- './config/html/**/*.html',
1099
- './config/html/**/*.ejs',
1100
- './config/html/**/*.hbs',
1101
- './src/**/*.js',
1102
- './src/**/*.jsx',
1103
- './src/**/*.ts',
1104
- './src/**/*.tsx',
1100
+ './src/**/*.{js,jsx,ts,tsx}',
1101
+ './config/html/**/*.{html,ejs,hbs}',
1105
1102
  './storybook/**/*',
1106
1103
  ],
1107
1104
  };
@@ -1113,10 +1110,14 @@ When the value is of type `object`, it is merged with the default configuration
1113
1110
 
1114
1111
  When the value is of type `Function`, the object returned by the function is merged with the default configuration via `Object.assign`.
1115
1112
 
1116
- The `theme` property is not allowed, otherwise the build will fail, using [`designSystem`](/api/config/design-system) as the `Tailwind CSS Theme` configuration.
1117
-
1118
1113
  The rest of the usage is the same as Tailwind CSS: [Quick Portal](https://tailwindcss.com/docs/configuration).
1119
1114
 
1115
+ ### Notes
1116
+
1117
+ Please note that if you are using the [designSystem](/api/config/design-system) configuration option simultaneously, the `theme` configuration of Tailwind CSS will be overridden by the value of `designSystem`.
1118
+
1119
+ The usage of other configurations follows the same approach as the official usage of Tailwind CSS. Please refer to [tailwindcss - Configuration](https://tailwindcss.com/docs/configuration) for more details.
1120
+
1120
1121
  ## target
1121
1122
 
1122
1123
  `target` is used to set the target environment for the generated JavaScript code. It enables Module Tools to transform JavaScript syntax that is not recognized by the target environment into older versions of JavaScript syntax that are compatible with these environments.
@@ -1179,6 +1180,51 @@ export default defineConfig({
1179
1180
 
1180
1181
  Reference the [Import Plugin - Notes](plugins/official-list/plugin-import.html#Notes)
1181
1182
 
1183
+ ## transformLodash
1184
+
1185
+ Specifies whether to modularize the import of [lodash](https://www.npmjs.com/package/lodash) and remove unused lodash modules to reduce the code size of lodash.
1186
+
1187
+ This optimization is implemented using [babel-plugin-lodash](https://www.npmjs.com/package/babel-plugin-lodash) and [swc-plugin-lodash](https://github.com/web-infra-dev/swc-plugins/tree/main/crates/plugin_lodash) under the hood.
1188
+
1189
+ - **Type**: `boolean`
1190
+ - **Default**: `true`
1191
+
1192
+ ### Example
1193
+
1194
+ This option is enabled by default, and Module Tools will automatically redirects the code references of `lodash` to sub-paths.
1195
+
1196
+ For example:
1197
+
1198
+ ```ts title="input.js"
1199
+ import _ from 'lodash';
1200
+ import { add } from 'lodash/fp';
1201
+
1202
+ const addOne = add(1);
1203
+ _.map([1, 2, 3], addOne);
1204
+ ```
1205
+
1206
+ The transformed code will be:
1207
+
1208
+ ```ts title="output.js"
1209
+ import _add from 'lodash/fp/add';
1210
+ import _map from 'lodash/map';
1211
+
1212
+ const addOne = _add(1);
1213
+ _map([1, 2, 3], addOne);
1214
+ ```
1215
+
1216
+ ### Disabling the Transformation
1217
+
1218
+ In some cases, the import transformation of `lodash` may generate unexpected code. In such cases, you can manually disable this optimization:
1219
+
1220
+ ```js title="modern.config.ts"
1221
+ export default defineConfig({
1222
+ buildConfig: {
1223
+ transformLodash: false,
1224
+ },
1225
+ });
1226
+ ```
1227
+
1182
1228
  ## umdGlobals
1183
1229
 
1184
1230
  Specify global variables for external import of umd artifacts
@@ -1221,7 +1267,6 @@ At this point the umd artifact will go to mount on `global.myLib`
1221
1267
 
1222
1268
  - The module name of the umd artifact must not conflict with the global variable name.
1223
1269
  - Module names will be converted to camelCase, e.g. `my-lib` will be converted to `myLib`, refer to [toIdentifier](https://github.com/babel/babel/blob/main/packages/babel-types/src/converters/toIdentifier.ts).
1224
-
1225
1270
  :::
1226
1271
 
1227
1272
  Also the function form can take one parameter, which is the output path of the current package file
@@ -647,7 +647,7 @@ const designSystem = {
647
647
  ```
648
648
 
649
649
  :::tip
650
- More about [TailwindCSS configuration](https://tailwindcss.com/docs/configuration#theme)
650
+ More about [Tailwind CSS configuration](https://tailwindcss.com/docs/configuration#theme)
651
651
  :::
652
652
 
653
653
  </details>
@@ -1,35 +1,21 @@
1
- ---
2
- sidebar_position: 7
3
- ---
4
-
5
1
  # Theme Configuration
6
2
 
7
- The module project provides the ability to configure themes through the [`designSystem`](/en/api/config/design-system) API.
8
-
9
- ## Motivation and rationale
10
-
11
- Theme configuration is somewhat similar to the custom theme functionality in the component library and is mainly used in style development. We can use the `designToken` generated by the `designSystem` configuration in different style development environments.
12
-
13
- The so-called `designToken` corresponds to different things in different style development environments.
3
+ Module Tools provides the ability to configure the Tailwind CSS theme through the `designSystem` option.
14
4
 
15
- - tailwindcss: use `designSystem` as the `theme` configuration for tailwindcss. So you can use.
16
- - The name of the HTML class supported by tailwindcss.
17
- - `@apply` custom directive under css/less/sass to use a string with the same name as the HTML class name supported by tailwindcss.
18
- - css/less/scss: Generate global style variables via `designSystem`.
5
+ ## Motivation and Principles
19
6
 
20
- The data structure of the `designSystem` API is borrowed from the [theme API](https://tailwindcss.com/docs/theme) in the `tailwindcss` configuration object, so a default set of `designToken` exists. For the default values, see the [`designSystem` API](/api/config/design-system).
7
+ Theme configuration is similar to custom theme functionality in component libraries and is primarily used for styling. When using `designSystem`, it serves as the `theme` configuration for Tailwind CSS. Therefore, you can use:
21
8
 
22
- :::info
23
- The css/less/sass global variables are not supported yet.
24
- :::
9
+ - CSS class names supported by Tailwind CSS.
10
+ - Strings with the same name as the CSS class names supported by Tailwind CSS, using the `@apply` custom directive in CSS/Less/Sass.
25
11
 
26
- ## Usage examples
12
+ For the default value of `designSystem`, refer to the [`designSystem` API](/api/config/design-system).
27
13
 
28
- ### tailwindcss
14
+ ## Usage Example
29
15
 
30
- When using tailwindcss, its [`theme`](https://v2.tailwindcss.com/docs/theme#extending-the-default-theme) configuration can be set via `designSystem`.
16
+ When using Tailwind CSS, you can use `designSystem` to configure its [`theme`](https://tailwindcss.com/docs/theme).
31
17
 
32
- For example, the following configuration extends the original color configuration:
18
+ For example, the following configuration extends the existing color configuration:
33
19
 
34
20
  ```ts title="modern.config.ts"
35
21
  export default {
@@ -43,9 +29,9 @@ export default {
43
29
  };
44
30
  ```
45
31
 
46
- We can have two ways of using tailwindcss in our code.
32
+ In the code, there are two ways to use Tailwind CSS.
47
33
 
48
- #### HTML Class
34
+ #### CSS Class Names
49
35
 
50
36
  ```tsx title="./src/index.tsx"
51
37
  import 'tailwindcss/utilities.css';
@@ -55,11 +41,9 @@ export default () => {
55
41
  };
56
42
  ```
57
43
 
58
- #### `@apply` Directives
44
+ #### `@apply` Directive
59
45
 
60
- :::info
61
- About [`@apply`](https://tailwindcss.com/docs/functions-and-directives#apply)。
62
- :::
46
+ Regarding [`@apply`](https://tailwindcss.com/docs/functions-and-directives#apply).
63
47
 
64
48
  ```tsx title="./src/index.tsx"
65
49
  import './index.css';
@@ -1097,13 +1097,8 @@ Tailwind CSS 相关配置。
1097
1097
  ```js title="modern.config.ts"
1098
1098
  const tailwind = {
1099
1099
  content: [
1100
- './config/html/**/*.html',
1101
- './config/html/**/*.ejs',
1102
- './config/html/**/*.hbs',
1103
- './src/**/*.js',
1104
- './src/**/*.jsx',
1105
- './src/**/*.ts',
1106
- './src/**/*.tsx',
1100
+ './src/**/*.{js,jsx,ts,tsx}',
1101
+ './config/html/**/*.{html,ejs,hbs}',
1107
1102
  './storybook/**/*',
1108
1103
  ],
1109
1104
  };
@@ -1115,10 +1110,14 @@ const tailwind = {
1115
1110
 
1116
1111
  值为 `Function` 类型时,函数返回的对象与默认配置通过 `Object.assign` 合并。
1117
1112
 
1118
- 不允许出现 `theme` 属性,否则会构建失败, 使用 [`designSystem`](/api/config/design-system) 作为 `Tailwind CSS Theme` 配置。
1119
-
1120
1113
  其他的使用方式和 Tailwind CSS 一致: [快速传送门](https://tailwindcss.com/docs/configuration)。
1121
1114
 
1115
+ ### 注意事项
1116
+
1117
+ 注意,如果你同时使用了 [designSystem](/api/config/design-system) 配置项,那么 Tailwind CSS 的 `theme` 配置将会被 `designSystem` 的值所覆盖。
1118
+
1119
+ 其他配置的使用方式与 Tailwind CSS 官方用法一致,请参考 [tailwindcss - Configuration](https://tailwindcss.com/docs/configuration)。
1120
+
1122
1121
  ## target
1123
1122
 
1124
1123
  `target` 用于为生成的 JavaScript 代码设置目标环境。它让 Module Tools 将目标环境无法识别的 JavaScript 语法转换为在这些环境中可用的低版本 JavaScript 语法。
@@ -1181,6 +1180,49 @@ export default defineConfig({
1181
1180
 
1182
1181
  参考[「Import 插件——注意事项」](plugins/official-list/plugin-import.html#注意事项)
1183
1182
 
1183
+ ## transformLodash
1184
+
1185
+ 是否模块化 [lodash](https://www.npmjs.com/package/lodash) 的导入,删除未使用的 lodash 模块,从而减少 lodash 代码体积。这项优化基于 [babel-plugin-lodash](https://www.npmjs.com/package/babel-plugin-lodash) 和 [swc-plugin-lodash](https://github.com/web-infra-dev/swc-plugins/tree/main/crates/plugin_lodash) 实现。
1186
+
1187
+ - 类型:`boolean`
1188
+ - 默认值:`true`
1189
+
1190
+ ### 示例
1191
+
1192
+ 该选项默认开启,Module Tools 会自动将 lodash 的代码引用指向子路径。
1193
+
1194
+ 比如:
1195
+
1196
+ ``` ts title="input.js"
1197
+ import _ from 'lodash';
1198
+ import { add } from 'lodash/fp';
1199
+
1200
+ const addOne = add(1);
1201
+ _.map([1, 2, 3], addOne);
1202
+ ```
1203
+
1204
+ 转换后的代码:
1205
+
1206
+ ```ts title="output.js"
1207
+ import _add from 'lodash/fp/add';
1208
+ import _map from 'lodash/map';
1209
+
1210
+ const addOne = _add(1);
1211
+ _map([1, 2, 3], addOne);
1212
+ ```
1213
+
1214
+ ### 关闭转换
1215
+
1216
+ 在个别情况下,lodash 的 import 转换可能会生成不符合预期的代码,此时你可以手动关闭这项优化:
1217
+
1218
+ ```js title="modern.config.ts"
1219
+ export default defineConfig({
1220
+ buildConfig: {
1221
+ transformLodash: false,
1222
+ },
1223
+ });
1224
+ ```
1225
+
1184
1226
  ## umdGlobals
1185
1227
 
1186
1228
  指定 UMD 产物外部导入的全局变量。
@@ -647,7 +647,7 @@ const designSystem = {
647
647
  ```
648
648
 
649
649
  :::tip
650
- 更多关于[TailwindCSS 配置](https://tailwindcss.com/docs/configuration#theme)
650
+ 更多关于[Tailwind CSS 配置](https://tailwindcss.com/docs/configuration#theme)
651
651
  :::
652
652
 
653
653
  </details>
@@ -4,30 +4,20 @@ sidebar_position: 6
4
4
 
5
5
  # 主题配置
6
6
 
7
- 模块工程通过 [`designSystem`](/api/config/design-system) API,提供了配置主题的能力。
7
+ Module Tools 通过 [`designSystem`](/api/config/design-system) 选项,提供了配置 Tailwind CSS 主题的能力。
8
8
 
9
9
  ## 动机和原理
10
10
 
11
- 主题配置有些类似组件库中的定制主题功能,主要用于样式开发中使用。我们可以通过 `designSystem` 配置在不同的样式开发环境下使用由它生成的 `designToken`。
11
+ 主题配置有些类似组件库中的定制主题功能,主要用于开发样式。当你使用 `designSystem` 时,它会作为 Tailwind CSS 的 `theme` 配置。因此你可以使用:
12
12
 
13
- 所谓 `designToken` 在不同的样式开发环境下对应不同的东西:
13
+ - Tailwind CSS 支持的 CSS 类名。
14
+ - 在 CSS/Less/Sass 下通过 `@apply` 自定义指令使用与 Tailwind CSS 支持的 CSS 类名同名的字符串。
14
15
 
15
- - tailwindcss: 以 `designSystem` 作为 tailwindcss 的 `theme` 配置。因此可以使用:
16
- - tailwindcss 支持的 HTML 类名。
17
- - 在 css/less/sass 下通过 `@apply` 自定义指令使用与 tailwindcss 支持的 HTML 类名同名的字符串。
18
- - css/less/scss: 通过 `designSystem` 生成全局的样式变量。
19
-
20
- `designSystem` API 的数据结构借鉴了 `tailwindcss` 配置对象中的 [theme API](https://tailwindcss.com/docs/theme),因此存在默认的一套 `designToken`。关于默认值,可以查看 [`designSystem` API](/api/config/design-system)。
21
-
22
- :::info
23
- 目前暂时还未支持 css/less/sass 全局变量。
24
- :::
16
+ 关于 `designSystem` 的默认值,可以查看 [`designSystem` API](/api/config/design-system)。
25
17
 
26
18
  ## 使用示例
27
19
 
28
- ### tailwindcss
29
-
30
- 在使用 tailwindcss 的时候,可以通过 `designSystem` 来设置它的 [`theme`](https://v2.tailwindcss.com/docs/theme#extending-the-default-theme) 配置。
20
+ 在使用 Tailwind CSS 的时候,可以通过 `designSystem` 来设置它的 [`theme`](https://tailwindcss.com/docs/theme) 配置。
31
21
 
32
22
  例如在下面的配置中扩展了原有的颜色配置:
33
23
 
@@ -43,9 +33,9 @@ export default {
43
33
  };
44
34
  ```
45
35
 
46
- 我们可以在代码中有两种使用 tailwindcss 的方式。
36
+ 在代码中,我们可以有两种使用 Tailwind CSS 的方式。
47
37
 
48
- #### HTML 类名
38
+ #### CSS 类名
49
39
 
50
40
  ```tsx title="./src/index.tsx"
51
41
  import 'tailwindcss/utilities.css';
package/package.json CHANGED
@@ -9,13 +9,13 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.31.2",
12
+ "version": "2.32.1",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
15
  "react": "^18.2.0",
16
16
  "react-dom": "^18.2.0",
17
- "@modern-js/doc-tools": "2.31.2",
18
- "@modern-js/doc-plugin-auto-sidebar": "2.31.2"
17
+ "@modern-js/doc-tools": "2.32.1",
18
+ "@modern-js/doc-plugin-auto-sidebar": "2.32.1"
19
19
  },
20
20
  "scripts": {
21
21
  "dev": "modern dev",