node.js package.json 中的多个命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46811149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple commands in package.json
提问by Redmonty
"start": "node server/server.js"- starting my server,
before this command i want auto command 'webpack';
"start": "node server/server.js"- 启动我的服务器,在此命令之前我想要自动命令'webpack';
npm run someCommandnpm run someCommand- 在终端必须使用webpackwebpack, than node server/server.jsnode server/server.js; 知道如何使用 gulp 配置它,但不想使用它))回答by Vladyslav Moisieienkov
If I understood you correctly, you want firstly run webpack and after compile run nodejs. Maybe try this:
如果我理解正确,你想先运行 webpack,然后编译运行 nodejs。也许试试这个:
"start": "webpack && node server/server.js"
回答by pdoherty926
The following shouldwork:
以下应该工作:
"start": "webpack && node server/server.js"
"start": "webpack && node server/server.js"
Though, for readability (and especially if you plan on adding additional tasks in the future), you may want to consider creating separate entries for each task and then calling each of those from start. So, something like:
但是,为了可读性(尤其是如果您计划在将来添加其他任务时),您可能需要考虑为每个任务创建单独的条目,然后从start. 所以,像这样:
{
"init-assets": "webpack",
"init-server": "node server/server.js",
"start": "npm run init-assets && npm run init-server"
}
回答by Nabin Kumar Khatiwada
You can also chain like this:
你也可以像这样链接:
"scripts": {
"clean": "npm cache clean --force",
"clean:complete": "npm run clean && npm uninstall -g @angular/cli && rmdir /Q /S node_modules",
"clean:complete:install": "npm run clean:complete && npm i -g @angular/cli && npm i && npm install --save-dev @angular/cli@latest"
}
回答by Bas Heerschop
You can use a tool like script-launcherto extend the features of you package.jsonfile.
您可以使用脚本启动器之类的工具来扩展package.json文件的功能。
With script-launcheryou can use arrays as scripts and reference another script with different arguments, and many more.
使用script-launcher,您可以使用数组作为脚本并使用不同的参数引用另一个脚本,等等。
Example using script arrays
使用脚本数组的示例
{
"scripts": {
"init": [
"webpack",
"node server/server.js"
]
}
}
Use the examples from the Table of Contentson how to implement this.
使用目录中的示例了解如何实现这一点。
回答by WebDever
Also, along with the accepted answer and @pdoherty926's answer, in case you want 2 command prompts running, you can add "start" before each command:
此外,连同接受的答案和@pdoherty926 的答案,如果您想要运行 2 个命令提示符,您可以在每个命令之前添加“开始”:
{
"init-assets": "webpack",
"init-server": "node server/server.js",
"start": "start npm run init-assets && start npm run init-server"
}
{
"init-assets": "webpack",
"init-server": "node server/server.js",
"start": "start npm run init-assets && start npm run init-server"
}

