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

完善 dirname 和 filename 的处理 #1734

Open
sorrycc opened this issue Dec 25, 2024 · 0 comments
Open

完善 dirname 和 filename 的处理 #1734

sorrycc opened this issue Dec 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@sorrycc
Copy link
Member

sorrycc commented Dec 25, 2024

问题

注:umijs/tnf#83 create-tnf 的打包先做了手动 patch 处理。

尝试打包以下结构的项目时,__dirname 的处理不能满足需求。

+ src/cli.ts
+ templates

cli.ts 里用了 path.join(__dirname, '../templates')。由于现在 platform: node 时会替换 __dirname 为相对路径 src,所以产物在运行时会读不到 templates 目录。

解法

感觉有两种思路,

1、替换 src/cli.ts 里的 path.join(__dirname, '../templates')path.join(require('path').join(__dirname, '../src'), '../templates'),这样就能找到 templates 目录。
2、提供配置项,允许关闭这个功能,保留 __dirname 也能解上面的问题,但有缺陷,只能覆盖 src 下一级文件里使用 __dirname 的场景。

1 更好。

参考

@sorrycc sorrycc added the enhancement New feature or request label Dec 25, 2024
@umijs umijs deleted a comment from petercat-assistant bot Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant