一 项目结构

cross-env:跨平台设置和使用环境变量

二 安装依赖

npm install --save-dev cross-env

三 npm脚本

 1 {
 2   "name": "demo",
 3   "version": "1.0.0",
 4   "description": "",
 5   "main": "index.js",
 6   "scripts": {
 7     "test": "echo \"Error: no test specified\" && exit 1",
 8     "eat":"cross-env fruit=lemon bash ./fruit.sh",
 9     "eat:mac":"fruit=apple && echo $fruit",
10     "eat:windows":"set fruit=banana && start D:\\project\\demo\\fruit.sh"
11   },
12   "keywords": [],
13   "author": "",
14   "license": "ISC"
15 }

四 脚本文件

###### Mac环境输出
echo $fruit;
###### Windows环境输出
echo %fruit%;

五 运行

1 Mac下使用cross-env(打印lemon)

npm run eat

 

2 Mac下直接运行(打印apple)

npm run eat:mac

 

3 Windows下直接运行(打印banana)

npm run eat:windows

 

相关文章:

  • 2022-12-23
  • 2021-06-07
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案