npm script 命令从另一个 package.json 运行脚本命令 [英] npm script command to run a script command from another package.json

查看:72
本文介绍了npm script 命令从另一个 package.json 运行脚本命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个单独的项目使用 npm - 所以我有两个:
some_base_folder/projectA/package.jsonsome_base_folder/projectB/package.json

I have two separate projects that use npm - so I have both :
some_base_folder/projectA/package.json and some_base_folder/projectB/package.json

这些文件中的每一个都有一个 scripts 部分.

Each of those files has a scripts section in it.

如果我转到 some_base_folder/projectA/ 并运行 npm run-script test 它会从 some_base_folder/projectA/package 的脚本部分执行测试命令.json 应该如此.

If I go to some_base_folder/projectA/ and run npm run-script test it executes the test command from the scripts section of some_base_folder/projectA/package.json as it should.

我可以将什么作为 "scripts": {test_projectA:'????'some_base_folder/projectB/package.json 中的值,以便当我在 some_base_folder/projectB/ 并且我运行 npm run-script test_projectA 它将是执行A项目的test脚本?

What can I put as the value of "scripts": {test_projectA:'????' in some_base_folder/projectB/package.json so that when I am in some_base_folder/projectB/ and I run npm run-script test_projectA it will be execute the test script of Project A?

我试过 ../projectA/npm run-script test 但它说:

'..' is not recognized as an internal or external command,
operable program or batch file.

我在 Windows 7 下运行,但更喜欢在 linux 上也能正常工作的解决方案.

I am running under windows 7 but would prefer a solution that would also work properly on linux.

推荐答案

其实很简单:

"scripts": {
  test_projectA:"cd ../projectA && npm run-script test"
}

这篇关于npm script 命令从另一个 package.json 运行脚本命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆