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

[Feature Request]: 支持 dotenv #2208

Closed
xezzon opened this issue Mar 13, 2023 · 4 comments
Closed

[Feature Request]: 支持 dotenv #2208

xezzon opened this issue Mar 13, 2023 · 4 comments
Assignees
Labels
feat New feature or request

Comments

@xezzon
Copy link

xezzon commented Mar 13, 2023

What problem does this feature solve?

构建时可以从以下环境中读取环境变量(优先级从低到高):

  • .env
  • .env.local
  • .env.[mode]
  • .env.[mode].local

将结果作为 Rspack 配置函数 的 env 参数(以上文件的优先级低于命令行的 env 参数)。并且自动将其设置到 process.env 中。

以 create-rspack 生成的项目,应该在 .gitignore 中包含 *.local ,以保证其只在本地生效,而不被 Git 追踪。

What does the proposed API of configuration look like?

参考 Vite 环境变量与模式

@xezzon xezzon added the feat New feature or request label Mar 13, 2023
@IWANABETHATGUY
Copy link
Contributor

IWANABETHATGUY commented Mar 13, 2023

我看看能不能直接用plugin 解决

@IWANABETHATGUY IWANABETHATGUY self-assigned this Mar 13, 2023
@IWANABETHATGUY
Copy link
Contributor

rspack-cli 目前的定位更偏向于 webpack-cli 不像 cra 或者 vite 所以我们可能会更加偏向使用 plugin 来支持

@IWANABETHATGUY
Copy link
Contributor

https://github.com/IWANABETHATGUY/rspack-plugin-dotenv
可以试试 安装这个包,你如果有更多定制化的需求,可以fork 一份自己修改,目前我们目标是兼容 webpack 生态,为了让 webpack 用户平滑迁移,可能不会让这个 plugin 变得和 vite一样。
你可以自己修改并且适配,修改方法非常简单,IWANABETHATGUY/rspack-plugin-dotenv@b982ad2#diff-bfe9874d239014961b1ae4e89875a6155667db834a410aaaa2ebe3cf89820556R53-R59

@xezzon
Copy link
Author

xezzon commented Mar 14, 2023

OK,有劳了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants