简体   繁体   English

如何添加browserify作为您的node.js应用程序的依赖项?

[英]How to add browserify as a dependency of your node.js application?

My node.js application depends on the fact browserify is available on the command line, as it uses it on a shell script. 我的node.js应用程序取决于浏览器可在命令行使用的事实,因为它在shell脚本中使用它。 How can I make sure it is available on the application without having to require my client to install it manually via npm install ? 如何确保不需要应用程序通过npm install手动安装它就可以在应用程序上使用它?

Since you're not giving too much context, I'm assuming that your external dependencies are located in ./node_modules in your app's directory. 由于您没有提供太多上下文,因此我假设您的外部依赖项位于应用程序目录中的./node_modules中。

In that case, just install browserify as an extra (local) dependency, which will make it available as ./node_modules/.bin/browserify . 在这种情况下,只需要安装browserify作为一个额外的(本地)的依赖,这将使其可以作为./node_modules/.bin/browserify That's also how you can refer to it from your shell script. 这也是从shell脚本中引用它的方式。

An even better option is to install browserify as follows: 更好的选择是按以下方式安装browserify:

npm install --save browserify

This not only installs browserify for you, but also adds it as a dependency to your dependencies in your package.json file. 这不仅会为您安装browserify,还将其作为依赖项添加到package.json文件中的依赖项中。

Now when someone installs your module ie via npm install yourmodule , browserify will be installed automatically into its ./node_modules . 现在,当有人安装您的模块(即通过npm install yourmodulenpm install yourmodule将自动安装到其./node_modules

This of course works for any module you depend on, not only browserify. 当然,这不仅适用于浏览器,还适用于您依赖的任何模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM