npm scripts --args All In One
npm scripts --args All In One
npm --
# linux
$
# windows
$
demo
# ??? -- reuse
$ npm run dev -- --port=8090 -- --env='pre'
$ npm run dev -- --port=8090 --env=pre
$ yarn dev --port=8090 --env='pre'
$ yarn dev --port=8090 --env=pre
const PROXYS = {
'dev': 'https://dev.xgqfrms.xyz'',
'pre': 'https://pre.xgqfrms.xyz',
'prod': 'https://prod.xgqfrms.xyz',
};
let PORT_ENV = 8080;
let PROXY_ENV = PROXYS['dev'];
// const args = argv.slice(2) || [];
for (let arg of process.argv) {
if (arg.startsWith('--port=')) {
const port = arg.replace('--port=', '');
if (port) {
PORT_ENV = Number.parseInt(port, 10);
}
}
if (arg.startsWith('--env=')) {
const env = arg.replace('--env=', '');
if (env) {
PROXY_ENV = PROXYS[env];
}
}
}
npm -- args
https://docs.npmjs.com/cli/v7/using-npm/config
https://docs.npmjs.com/cli/v7/using-npm/config#command-line-flags
$ --flag
# 等价于
$ --flag=true
https://www.twilio.com/blog/npm-scripts
https://www.npmjs.com/package/nrm
refs
https://docs.npmjs.com/cli/v7/
https://www.runoob.com/nodejs/nodejs-npm.html
https://www.ruanyifeng.com/blog/2016/10/npm_scripts.html
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15419474.html
未经授权禁止转载,违者必究!