-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
"scripts": {
"view": "echo $npm_config_branch && echo done"
}npm run view --branch=master
mp-app-home@1.0.1 view
echo $npm_config_branch && echo done
master
done
但是使用 pnpm 的时候,拿不到这个变量。文档上好像没有提到怎么传参,只是说运行 pnpm run --foo=bar 和 webpack --foo=bar效果一样。
我们可以试用 yargs 来获取参数。
#!/usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
// hideBin 相当于 process.argv.slice(2)
const argv = yargs(hideBin(process.argv)).parse()
console.log(argv.branch)pnpm run prod --branch=master
master
Metadata
Metadata
Assignees
Labels
No labels