一 项目结构
二 安装依赖
npm install --save-dev cross-env
三 npm脚本
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"eat":"cross-env fruit=lemon bash ./fruit.sh",
"eat:mac":"fruit=apple && echo $fruit",
"eat:windows":"set fruit=banana && start D:\\project\\demo\\fruit.sh"
},
"keywords": [],
"author": "",
"license": "ISC"
}
四 脚本文件
###### 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