Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add exports fields #12944

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/vant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
"typings": "lib/index.d.ts",
"unpkg": "lib/vant.min.js",
"jsdelivr": "lib/vant.min.js",
"exports": {
".": {
"import": "./es/index.mjs",
"require": "./lib/vant.cjs.js",
"types": "./lib/index.d.ts"
},
"./lib": {
"import": "./lib/vant.es.js",
"require": "./lib/vant.cjs.js",
"types": "./lib/index.d.ts"
},
"./es": {
"import": "./es/index.mjs",
"types": "./es/index.d.ts"
},
"./lib/*.js": {
"require": "./lib/*.js",
"types": "./lib/*.d.ts"
},
"./es/*.mjs": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es/*.mjs 只能导出 lib 下面一级的文件,但是没法导出 es/button/style/index.mjs 这种多级目录的文件

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考 #10348

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是可以导出多级目录的。node 文档

  • maps expose nested subpaths as it is a string replacement syntax only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

咦,还真是。。

那当时是另一个问题了,原来允许忽略 index.mjs,加上 exports 以后不行了

比如 import 'vant/es/button/style':

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在没有后缀的地址会增加 /index.m?js

这样会出现一个问题

vant/es/button/Button -> vant/es/button/Button/index.mjs

只有 vant/es/button/Button.mjs -> vant/es/button/Button.mjs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,添加 exports fields 还是会有潜在的 breaking 风险,通常来说放在大版本里发布比较合适,我们可以先看一下 Nuxt 全局方法的类型问题有没有其他解决方法。。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, 我先看看官方提供的增加类型可以用不

"import": "./es/*.mjs",
"types": "./es/*.d.ts"
},
"./*": "./*"
},
"files": [
"es",
"lib"
Expand Down