如何以跨平台的方式设置环境变量? [英] How to set environment variables in a cross-platform way?

查看:73
本文介绍了如何以跨平台的方式设置环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Windows,我的Node脚本应如下所示:

For Windows, my Node scripts should look like this:

"scripts": {
    "start-docs": "SET NODE_ENV=development&&babel-node ./docs/Server.js"
}

但是在Linux上没有 SET ,所以它会是这样的:

But on Linux there's no SET, so it would be like this:

"scripts": {
    "start-docs": "NODE_ENV=development&&babel-node ./docs/Server.js"
}

有没有办法以一致且跨平台的方式声明环境变量?

Is there a way to declare environment variables in a way that is consistent and cross-platform?

推荐答案

我最近遇到了环境项目。这非常简单

I recently came across the cross-env project. It's pretty straight-forward

{
  "scripts": {
    "build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
  }
}

无论操作系统如何,这都会将 build 环境变量设置为 production

That will set the build environment variable to production regardless of the OS.

这篇关于如何以跨平台的方式设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆