将JS包作为npm脚本调用到另一个包中



我有一个包Package2,它依赖于package 1

包1:由以下文件组成(对于本例(

package.json
index.js
/bin/package1 (no extension)

包1包.json:

...
{
"name": "package1",
"version": "0.0.1",
"description": "a JavaScript library that should be called by other stuff",
"main": "index.js",
"scripts": {
"bin": "cli.js"
},
...

包1/bin/package1脚本:


#!/usr/bin/env node
const package1 = require('../'); 
// just import the package1 module an it should run  without function call

程序包2是一个依赖于程序包1的程序包。

包2包.json:

...
"name": "package2",
"version": "1.0.0",
"description": "a JavaScript library that depends on package1",
"main": "index.js",
"scripts": {
"serve" : "package1 ."
},
...

但当我运行yarn serve:时,我遇到了一个错误

yarn run v1.22.17
$ package1 .
'package1' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我试过很多不同的东西,但我无法让它发挥作用。

您需要在"脚本";标记到包1的包.json:


...
"scripts": {....},
"bin": {
"package1": "bin/package1"
},
...

就是

最新更新