我的一个朋友建议使用
cross-env
这基本上解决了我的问题。
在使用该包之前,我只分析了
process.argv
具有以下代码的数组:
const commandLineArguments = (argumentList => {
let parsedArguments = {}, index, option, thisOption, currentOption;
for (index = 0; index < argumentList.length; index++) {
thisOption = argumentList[index].trim();
option = thisOption.replace(/^\-+/, '');
if (option === thisOption) {
if (currentOption) {
parsedArguments[currentOption] = option;
}
currentOption = null;
} else {
currentOption = option;
parsedArguments[currentOption] = true;
}
}
return parsedArguments;
})(process.argv);
使用类似的呼叫
gulp --target electron --configuration development
我可以这样访问这些参数:
const targetPlatform = {
isElectron: commandLineArguments.target === "electron",
isWeb: commandLineArguments.target === "web"
};
// Default setting if no option was supplied
if (!targetPlatform.isElectron && !targetPlatform.isWeb) {
targetPlatform.isElectron = true;
}