Skip to content

Commit 2b0fe73

Browse files
committed
docs: update README
1 parent 1bb3dff commit 2b0fe73

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,9 @@ enum-plus is designed to be compatible with a wide range of environments, includ
955955
956956
### Browser Environments
957957
958-
- **Modern Bundlers**: For bundlers supporting the [exports](https://nodejs.org/api/packages.html#exports-sugar) field (such as webpack 5+, vite, rollup), `es` directory is imported, which targets `ES2020`. If you need to support earlier browsers, you can use `@babel/preset-env` to transpile to earlier syntax during the build process.
958+
- **Modern Bundlers**: For bundlers supporting the [exports](https://nodejs.org/api/packages.html#exports-sugar) configuration (such as webpack 5+, vite, rollup), `es` directory is imported, which targets `ES2020`. If you need to support earlier browsers, you can use `@babel/preset-env` to transpile to earlier syntax during the build process.
959959
960-
- **Legacy Bundlers**: For bundlers without [exports](https://nodejs.org/api/packages.html#exports-sugar) field support (like Webpack 4), this library automatically falls back to the `main` field entry point, and `es-legacy` directory is imported, which targets `ES2015`.
960+
- **Legacy Bundlers**: For bundlers without [exports](https://nodejs.org/api/packages.html#exports-sugar) configuration support (like Webpack 4), this library automatically falls back to the `main` field entry point, and `es-legacy` directory is imported, which targets `ES2015`.
961961
962962
- **UMD Version**: For direct browser usage or static projects without bundlers, enum-plus provides UMD format files in the `umd` directory. These can be included via a `<script>` tag and accessed through `window.EnumPlus`. The UMD directory offers two versions:
963963
@@ -972,7 +972,13 @@ enum-plus is designed to be compatible with a wide range of environments, includ
972972
973973
### **Node.js Environments**
974974
975-
In Node.js environments, the default import path is the `lib` directory, which targets **`ES2016`**. This is compatible with Node.js `v7.x` and above.
975+
In Node.js environments, the EcmaScript version provided is **`ES2016`**.
976+
977+
Additionally, enum-plus supports both `CommonJS` and `ESModule` module formats.
978+
979+
- For versions that support the [exports](https://nodejs.org/api/packages.html#exports-sugar) configuration (e.g., Node 14+), you can choose to use either `require` or `import` syntax to import the module.
980+
- For earlier Node.js versions, the default import is from the `lib` directory, which only supports the `CommonJS` module format, meaning you can only use the `require` syntax.
981+
- The minimum compatible version of Node.js is `v7.x`.
976982
977983
---
978984

README.zh-CN.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,9 @@ enum-plus 设计之初就考虑了广泛的兼容性需求,可无缝运行于
953953

954954
### 浏览器环境
955955

956-
- **现代打包工具**:对于支持 [exports](https://nodejs.org/api/packages.html#exports-sugar) 字段的打包工具(如 webpack 5+、vite、rollup),引入的是 `es` 目录,对应的 EcmaScript 版本是 **`ES2020`**。如果需要支持更早期的浏览器,可以在构建过程中使用 `@babel/preset-env` 转译为更早期的语法。
956+
- **现代打包工具**:对于支持 [exports](https://nodejs.org/api/packages.html#exports-sugar) 配置的打包工具(如 webpack 5+、vite、rollup),引入的是 `es` 目录,对应的 EcmaScript 版本是 **`ES2020`**。如果需要支持更早期的浏览器,可以在构建过程中使用 `@babel/preset-env` 转译为更早期的语法。
957957

958-
- **旧版打包工具**:对于不支持 [exports](https://nodejs.org/api/packages.html#exports-sugar) 字段的工具(如 webpack 4),enum-plus 会自动回退到 `main` 字段的入口点,引入的是 `es-legacy` 目录,对应的 EcmaScript 版本是 **`ES2015`**。
958+
- **旧版打包工具**:对于不支持 [exports](https://nodejs.org/api/packages.html#exports-sugar) 配置的工具(如 webpack 4),enum-plus 会自动回退到 `main` 字段的入口点,引入的是 `es-legacy` 目录,对应的 EcmaScript 版本是 **`ES2015`**。
959959

960960
- **UMD版本**:为了方便在浏览器中直接使用,或者方便在没有打包工具的静态项目中使用,enum-plus 还提供了 UMD 版本,存放在 `umd` 目录下。UMD 格式的文件可以通过 `<script>` 标签直接引入,通过 `window.EnumPlus` 获取类库内容。umd 目录提供了两种版本:
961961

@@ -970,7 +970,13 @@ enum-plus 设计之初就考虑了广泛的兼容性需求,可无缝运行于
970970

971971
### Node.js 环境
972972

973-
Node.js 环境下,默认引入的是 `lib` 目录,对应的 EcmaScript 版本是 **`ES2016`**,可以兼容 Node.js `v7.x` 及以上版本
973+
Node.js 环境下,提供的EcmaScript 版本是 **`ES2016`**
974+
975+
另外,enum-plus 同时支持`CommonJS``ESModule` 两种模块格式。
976+
977+
- 对于支持 [exports](https://nodejs.org/api/packages.html#exports-sugar) 配置的版本(例如Node14+),可以自行选择使用 `require` 或 `import` 语法来引入模块。
978+
- 对于更早期的 Node.js 版本,默认默认引入的是 `lib` 目录,只能使用 `CommonJS` 模块格式,即 `require` 语法。
979+
- 最低可以兼容 Node.js `v7.x` 版本。
974980

975981
---
976982

0 commit comments

Comments
 (0)