我如何 运行 来自已安装的 NPM 包的脚本?
How can I run a script from an already installed NPM package?
示例:
npm install my-tools
npm run my-tools tool1
这不起作用 - 它寻找 "package.json in my current directory. The documentation for "npm 运行" 说:
If no package name is provided, it will search for a package.json in
the current folder
(https://docs.npmjs.com/cli/run-script)
那么我怎样才能提供包名呢?
您似乎正在尝试 运行 my-tools
的 package.json
中定义的脚本。自 npm@2.0.0
.
起不支持此功能
引用 npm run-script
包名是文档错误;我在 npm
问题跟踪器上为此创建了一个问题:https://github.com/npm/npm/issues/7440
一些备选方案可能包括:
使用npm explore
临时将当前目录(等)设置到包中,例如,npm explore my-tools -- npm run tool1
将 tool1
等发布为 package.json
中的 bin
条目,而不是 scripts
;这将使它们可以通过命令行访问
根据您的需要,您可能会发现更重量级的任务 运行 比 npm
脚本和二进制文件更好的方法 grunt
示例:
npm install my-tools
npm run my-tools tool1
这不起作用 - 它寻找 "package.json in my current directory. The documentation for "npm 运行" 说:
If no package name is provided, it will search for a package.json in the current folder
(https://docs.npmjs.com/cli/run-script)
那么我怎样才能提供包名呢?
您似乎正在尝试 运行 my-tools
的 package.json
中定义的脚本。自 npm@2.0.0
.
引用 npm run-script
包名是文档错误;我在 npm
问题跟踪器上为此创建了一个问题:https://github.com/npm/npm/issues/7440
一些备选方案可能包括:
使用
npm explore
临时将当前目录(等)设置到包中,例如,npm explore my-tools -- npm run tool1
将
tool1
等发布为package.json
中的bin
条目,而不是scripts
;这将使它们可以通过命令行访问根据您的需要,您可能会发现更重量级的任务 运行 比
npm
脚本和二进制文件更好的方法grunt