@modern-js/module-tools-docs 2.31.2 → 2.32.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,17 @@
1
1
  # @modern-js/module-tools-docs
2
2
 
3
+ ## 2.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8d22b87: docs: add content about transformLodash and fix a error about english content
8
+ docs: 添加关于 transformLodash 的内容,并且修复一个英文内容的错误
9
+
10
+ ### Patch Changes
11
+
12
+ - @modern-js/doc-plugin-auto-sidebar@2.32.0
13
+ - @modern-js/doc-tools@2.32.0
14
+
3
15
  ## 2.31.2
4
16
 
5
17
  ### 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
  };
@@ -1179,6 +1176,51 @@ export default defineConfig({
1179
1176
 
1180
1177
  Reference the [Import Plugin - Notes](plugins/official-list/plugin-import.html#Notes)
1181
1178
 
1179
+ ## transformLodash
1180
+
1181
+ 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.
1182
+
1183
+ 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.
1184
+
1185
+ - **Type**: `boolean`
1186
+ - **Default**: `true`
1187
+
1188
+ ### Example
1189
+
1190
+ This option is enabled by default, and Module Tools will automatically redirects the code references of `lodash` to sub-paths.
1191
+
1192
+ For example:
1193
+
1194
+ ```ts title="input.js"
1195
+ import _ from 'lodash';
1196
+ import { add } from 'lodash/fp';
1197
+
1198
+ const addOne = add(1);
1199
+ _.map([1, 2, 3], addOne);
1200
+ ```
1201
+
1202
+ The transformed code will be:
1203
+
1204
+ ```ts title="output.js"
1205
+ import _add from 'lodash/fp/add';
1206
+ import _map from 'lodash/map';
1207
+
1208
+ const addOne = _add(1);
1209
+ _map([1, 2, 3], addOne);
1210
+ ```
1211
+
1212
+ ### Disabling the Transformation
1213
+
1214
+ In some cases, the import transformation of `lodash` may generate unexpected code. In such cases, you can manually disable this optimization:
1215
+
1216
+ ```js title="modern.config.ts"
1217
+ export default defineConfig({
1218
+ buildConfig: {
1219
+ transformLodash: false,
1220
+ },
1221
+ });
1222
+ ```
1223
+
1182
1224
  ## umdGlobals
1183
1225
 
1184
1226
  Specify global variables for external import of umd artifacts
@@ -1221,7 +1263,6 @@ At this point the umd artifact will go to mount on `global.myLib`
1221
1263
 
1222
1264
  - The module name of the umd artifact must not conflict with the global variable name.
1223
1265
  - 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
1266
  :::
1226
1267
 
1227
1268
  Also the function form can take one parameter, which is the output path of the current package file
@@ -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
  };
@@ -1181,6 +1176,49 @@ export default defineConfig({
1181
1176
 
1182
1177
  参考[「Import 插件——注意事项」](plugins/official-list/plugin-import.html#注意事项)
1183
1178
 
1179
+ ## transformLodash
1180
+
1181
+ 是否模块化 [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) 实现。
1182
+
1183
+ - 类型:`boolean`
1184
+ - 默认值:`true`
1185
+
1186
+ ### 示例
1187
+
1188
+ 该选项默认开启,Module Tools 会自动将 lodash 的代码引用指向子路径。
1189
+
1190
+ 比如:
1191
+
1192
+ ``` ts title="input.js"
1193
+ import _ from 'lodash';
1194
+ import { add } from 'lodash/fp';
1195
+
1196
+ const addOne = add(1);
1197
+ _.map([1, 2, 3], addOne);
1198
+ ```
1199
+
1200
+ 转换后的代码:
1201
+
1202
+ ```ts title="output.js"
1203
+ import _add from 'lodash/fp/add';
1204
+ import _map from 'lodash/map';
1205
+
1206
+ const addOne = _add(1);
1207
+ _map([1, 2, 3], addOne);
1208
+ ```
1209
+
1210
+ ### 关闭转换
1211
+
1212
+ 在个别情况下,lodash 的 import 转换可能会生成不符合预期的代码,此时你可以手动关闭这项优化:
1213
+
1214
+ ```js title="modern.config.ts"
1215
+ export default defineConfig({
1216
+ buildConfig: {
1217
+ transformLodash: false,
1218
+ },
1219
+ });
1220
+ ```
1221
+
1184
1222
  ## umdGlobals
1185
1223
 
1186
1224
  指定 UMD 产物外部导入的全局变量。
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.0",
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-plugin-auto-sidebar": "2.32.0",
18
+ "@modern-js/doc-tools": "2.32.0"
19
19
  },
20
20
  "scripts": {
21
21
  "dev": "modern dev",