-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: add package files support #6942
feat: add package files support #6942
Conversation
package.json 中的 files 大多都是通配而不是实际的地址,能否举个例子说明下这个场景 |
源码: /**
* The page's HTML template structure, using JSX.
*/
import { Meta, Title, Links, Scripts, Main } from 'ice';
import { description } from '../package.json';
// @ali/[email protected]
import SkeletonRoot from '@ali/odin-jp-ui/src/skeleton/skeleton-root';
export default function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content={description} />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover" />
<Meta />
<Title />
<Links />
</head>
<body>
<SkeletonRoot></SkeletonRoot>
<Main></Main>
<script src="https://g.alicdn.com/??mtb/lib-windvane/3.0.7/windvane.js" />
<Scripts />
</body>
</html>
);
} 二方包的package.json {
...
"name": "@ali/odin-jp-ui",
"version": "0.0.1-beta.93",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"es",
"lib",
"src/skeleton/skeleton-root.tsx"
],
...
} 这里因为二方包并没有exports和module的导出,源码中引入files里的指定文件,经过ice的prebundle实际上会加载lib/index.js,不符合预期 |
即便files是通配路径,在import通配路径里的指定文件,经过prebundle的处理,找不到exports 或者 module模块之后,降级到index.js。这里我觉的在降级的同时,最好能给出日志提醒,否则还是挺困惑的。 |
这个 case 我理解应该不依赖 files,如果 resolveExports 和 resolveLegacy 都无法获取的情况下,应该尝试通过类似 require.resolve 来看下是否可以正确获取到子路径,如果可以就把这个路径作为 entry 独立打包,预打包场景下即便有重复逻辑 影响应该也不大 |
是的,你说的是对的,更合理的是看下能否获得正确的子路径,最后再降级到index.js,我修改下吧 |
这个二方包的index.js里有window和location,阻塞预打包了 |
这个是另外的问题? 如果是预打包报错的问题,可以通过另外的 issue 解决 |
是的,看看这个 兼容指定文件导入的代码呢,刚提交的 |
CI 错误看下,应该是类型问题 |
提交了,兼容了legacy的返回类型 |
@@ -1,4 +1,5 @@ | |||
import path from 'path'; | |||
import fs from 'fs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
统一使用 fse(fs-extra)吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@wssgcg1213 please help to review |
fix #6941
在使用ice的过程中,发现对files白名单导出的es文件是不支持的,看源码是获取了main,其实并不是加载对应的files里的文件。