Skip to content

Commit

Permalink
chore: 更新条件导出
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden-FE committed Mar 18, 2024
1 parent b26e578 commit c70bba2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import { formatDate } from '@compass-aiden/helpers';
import * as allHelpers from '@compass-aiden/helpers';
// 通过别名路径导入esm文件
import { formatDate } from '@compass-aiden/helpers/esm';
// 导入umd文件
import '@compass-aiden/helpers/umd';
```

浏览器script标签安装:

```html
<!-- 请根据个人需求采用unpkg或者jsdelivr链接 -->
<script src="https://unpkg.com/@compass-aiden/helpers@0.0.1/dist/compass-helpers.umd.js"></script>
<script src="https://unpkg.com/@compass-aiden/helpers@latest/dist/compass-helpers.umd.js"></script>
<script>
console.log(window.CompassHelpers.formatDate());
</script>
Expand All @@ -42,14 +40,16 @@ npm方式安装:
`npm install @compass-aiden/helpers`

```typescript
// 自动识别导入cjs文件, 如果无法识别为cjs导入, 可在tsconfig 设置 { "module": "NodeNext", "moduleResolution": "NodeNext" }或通过其他方式导入
import { createFile } from '@compass-aiden/helpers';
// 全量导入
import * as allHelpers from '@compass-aiden/helpers';
// 通过别名路径导入cjs文件
import { createFile } from '@compass-aiden/helpers/cjs';
// 自动导入cjs文件
const { createFile } = require('@compass-aiden/helpers');
// 全量导入
const { createFile } = require('@compass-aiden/helpers');

/** 在type: module启用ESM环境下,请参考如下方式 */
// 通过别名路径导入cjs文件,如果不能识别条件导出,tsconfig可设置 `{ "moduleResolution": "bundler" }`
import { createFile } from '@compass-aiden/helpers/cjs';
// 自动导入默认cjs文件, 当 tsconfig 配置包含 `{ "moduleResolution": "NodeNext" }`时可用
import { createFile } from '@compass-aiden/helpers';
```

## Contributes
Expand Down
27 changes: 11 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
{
"name": "@compass-aiden/helpers",
"type": "module",
"version": "0.1.0",
"version": "0.1.1",
"description": "实用程序库",
"main": "dist/compass-helpers.umd.js",
"main": "dist/web.es.js",
"typings": "types/web.es.d.ts",
"jsdelivr": "dist/compass-helpers.umd.js",
"unpkg": "dist/compass-helpers.umd.js",
"exports": {
".": {
"types": {
"import": "./types/web.es.d.ts",
"require": "./types/node.d.cts",
"default": "./types/compass-helpers.umd.d.ts"
"require": "./types/node.d.ts",
"default": "./types/web.es.d.ts"
},
"import": "./dist/web.es.js",
"require": "./dist/node.cjs",
"default": "./dist/compass-helpers.umd.js"
"require": "./dist/node.js",
"default": "./dist/web.es.js"
},
"./dist/*": "./dist/*",
"./types/*": "./types/*",
"./cjs": {
"types": "./types/node.d.cts",
"default": "./dist/node.cjs"
"types": "./types/node.d.ts",
"default": "./dist/node.js"
},
"./esm": {
"types": "./types/web.es.d.ts",
"default": "./dist/web.es.js"
},
"./umd": {
"types": "./types/compass-helpers.umd.d.ts",
"default": "./dist/compass-helpers.umd.js"
}
"./dist/*": "./dist/*",
"./types/*": "./types/*"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default [
output: getOutput({
format: 'cjs',
exports: 'auto',
entryFileNames: '[name].[format]',
entryFileNames: '[name].js',
}),
external: getExternal(),
plugins: getPlugins({
Expand Down

0 comments on commit c70bba2

Please sign in to comment.