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

server目录下env问题(环境变量问题解答) #5

Open
unfetteredman2020 opened this issue Nov 2, 2022 · 9 comments
Open

server目录下env问题(环境变量问题解答) #5

unfetteredman2020 opened this issue Nov 2, 2022 · 9 comments

Comments

@unfetteredman2020
Copy link

两个问题:
1,入口index里面配置dotenv,看引入路径是引入的其实是根目录下的.env文件,但其实master上面根目录没有这个文件;
2,script里面dev下的index,为什么要read 一下env目录下的env.template文件,最后又去write进原文件?

@Lrunlin
Copy link
Owner

Lrunlin commented Nov 2, 2022

启动之后会把.env和.env.dev合并成一个env文件放到dist里面,然后index去读取.env

@unfetteredman2020
Copy link
Author

启动之后会把.env和.env.dev合并成一个env文件放到dist里面,然后index去读取.env

那第二个问题呢?

@Lrunlin
Copy link
Owner

Lrunlin commented Nov 2, 2022

对于env.template文件是写入,对于dev是去读,因为防止把一些密钥上传到github上面,每次运行都会生成一个env.template文件用来修改成对应开发环境的环境变量,具体可以查看readme中的环境变量
image

@Lrunlin Lrunlin changed the title server目录下env问题 server目录下env问题(环境变量问题解答) Nov 2, 2022
@unfetteredman2020
Copy link
Author

了解,但是还是有个疑问点,index里面引入的.env ,根目录下是没有的,这个怎么解释?

@Lrunlin
Copy link
Owner

Lrunlin commented Nov 2, 2022

因为TSC的速度非常慢,所以项目其实使用了增量编译,在启动时tsc在开发时增量编译TS文件
image

image

总的来说其实node.js运行的dist下的文件,在项目启动时TSC后自动吧env文件(.env、.env.dev)移动合并至dist
image

@Lrunlin
Copy link
Owner

Lrunlin commented Nov 2, 2022

因为server中涉及到七牛云的key,所以才使用了这个方法,有空的话可能会使用git hook来解决

@unfetteredman2020
Copy link
Author

了解,但是还是有个疑问点,index里面引入的.env ,根目录下是没有的,这个怎么解释?

看到你的截图我就知道了,master上你没有上传.env 文件,感谢您的答疑解惑

@Lrunlin
Copy link
Owner

Lrunlin commented Nov 2, 2022

没事的,感兴趣的话可以点个star

@unfetteredman2020
Copy link
Author

哈哈,没问题

@Lrunlin Lrunlin closed this as completed Nov 2, 2022
@Lrunlin Lrunlin reopened this Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants