当先锋百科网

首页 1 2 3 4 5 6 7

一 项目结构

二 安装依赖

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

 

转载于:https://www.cnblogs.com/sea-breeze/p/10082823.html