command-line - How to pass env var to Docusaurus v2
问题描述
I've been trying to get environment variables to work in my documentation build.
I've had some success with adding a dotenv-webpack
plugin and substituting values that way.
This has the downside of needing a .env
file of some kind
I would like to have my build know of environment variables automatically ie. everything that is output from printenv
I've tried adding this to package.json:
TEST_ENV_VAR=working docusaurus start"
But when I log the process.env
object there is nothing there.
How can I make this work?
解决方案
我创建了一个插件,将功能添加dotenv-webpack
到 Docusaurus2 的 webpack 配置中。
https://www.npmjs.com/package/docusaurus2-dotenv
您应该能够npm install docusaurus2-dotenv
、启用systemvar
并将其添加到您的插件部分,并且您的systemvar
值将可以访问,例如process.env.PATH
。
这将允许您使用.env
文件(如果您决定在将来使用它们),以及在 CI 期间创建或存在于构建代码的机器上的任何环境变量。
docusaurus.config.js
module.exports = {
..., // other docusaurus2 config
plugins: [
[
"docusaurus2-dotenv",
{
systemvars: true,
},
],
],
}
推荐阅读
- android - 我想使用Android App从firebase中单独获取所有数据
- android - “android:windowLightStatusBar”不起作用
- vue.js - 在 Quasar/Vue 中触发/更新从子组件到父组件的数据更改,以防子组件具有项目列表
- java - 禁用 Spring Cloud 配置客户端
- javascript - 如何使用 Vue CLI 一次将多个 Vue.js 组件构建为原生 Web 组件?
- laravel - 关闭浏览器时,Laravel 登录过期
- git - 如何在 GitLab-runner 中使用 Git 命令?
- html - 如何在 Django 中实现特定于对象的模式?
- python - 当有其他参数时如何在Django中绑定表单
- php - Ionic Angular Query 字符串解析以登录