[英]Call JS package as npm script into another package
我有一個依賴於 Package1 的package Package2 。
Package 1 :由以下文件組成(對於本例)
package.json
index.js
/bin/package1 (no extension)
Package 1 package.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"
},
...
Package 1 /bin/package1 腳本:
#!/usr/bin/env node
const package1 = require('../');
// just import the package1 module an it should run without function call
Package 2是依賴於 package1 的 package。
Package 2 package.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.
我嘗試了很多不同的東西,但我無法讓它工作。
您需要在“腳本”標簽之后將其添加到package 1的 package.json 中:
...
"scripts": {....},
"bin": {
"package1": "bin/package1"
},
...
就是這樣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.