[英]Move script used in package.json to npm package
I have a file tools.js that sits in the root directory of each of our plugins.我有一个文件 tools.js,它位于我们每个插件的根目录中。 It has a build function which helps create a build for the plugin.
它有一个构建 function 有助于为插件创建构建。 It is used by the package.json file like so:
package.json 文件使用它,如下所示:
"scripts": {
"build:node": "node -e 'require(\"./tools\").build()'",
}
Rather than needing to have this file included in every plugin's folder, I would like to put it into our node package which is required by all of our plugins, so that it can just be added by someone running npm install.我不想将这个文件包含在每个插件的文件夹中,我想把它放到我们所有插件都需要的节点 package 中,这样它就可以由运行 npm 安装的人添加。 That part is simple enough, but I don't know how to then access it and call one of its functions from the original package.json file.
该部分很简单,但我不知道如何访问它并从原始 package.json 文件中调用其功能之一。
This is probably straightforward but I don't have much experience with NPM so would really appreciate any advice.这可能很简单,但我对 NPM 没有太多经验,所以非常感谢任何建议。
Just to clarify, the folders currently look like this:澄清一下,这些文件夹目前如下所示:
plugin1/
package.json
tools.js
node_modules/
our_node_package/ (where I want tools.js to be called from)
You should publish the package to NPM, and then you can use it by installing it.您应该将package发布到NPM,然后安装即可使用。
Here is a guide to publishing your package to the NPM.这是将 package 发布到 NPM 的指南。 https://zellwk.com/blog/publish-to-npm/
https://zellwk.com/blog/publish-to-npm/
New Answer:新答案:
There are 2 possible ways:有两种可能的方式:
One way would be: your_npm_package
is the published package name.一种方法是:
your_npm_package
是已发布的 package 名称。
"scripts": {
"build:node": "node ./node_modules/your_npm_package/tools.js",
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.