简体   繁体   English

您可以不使用NodeJS而使用npm软件包吗

[英]Can you use a npm package without using NodeJS

I found a library on github that I would like to use but the download instructions only mention using npm but I am not using a NodeJS project (just a basic html,css,javascript front-end with no back-end server). 我在github上找到了一个我想使用的库,但下载说明仅提到了使用npm的情况,但我没有使用NodeJS项目(只是一个基本的html,css,javascript前端,没有后端服务器)。 Am I still able to use that library or is it a lost cause? 我仍然可以使用该库吗?或者它是一个丢失的原因? Is there another way to download it without using npm? 是否有另一种无需使用npm即可下载它的方法?

Is there another way to download it without using npm? 是否有另一种无需使用npm即可下载它的方法?

If it's on github, then you can checkout or fork the repository as you can with any other git repo. 如果它在github上,那么您可以像使用任何其他git repo一样签出或存储库。

Am I still able to use that library or is it a lost cause? 我仍然可以使用该库吗?或者它是一个丢失的原因?

Whether or not the library will work without Node will depend on the library. 库是否可以在没有Node的情况下运行取决于库。

If it presents itself as a Node module, then you'll probably have to modify it (or find a compatible module loader for browser-side JS). 如果它本身显示为Node模块,那么您可能必须对其进行修改(或为浏览器端JS找到兼容的模块加载器)。

If it depends on NodeJS features (such as the filesystem API) then you'll be out of luck (unless, for example, you polyfill them to work across HTTP) 如果它依赖于NodeJS功能(例如文件系统API),那么您将很不走运(除非,例如,将其填充以跨HTTP使用)

If you use a build tool such as browserify , or webpack , you can author scripts that require node modules and the build tool will generate a script that includes all the necessary dependencies (assuming that the necessary dependencies are compatible with client-side JavaScript environments). 如果您使用一个构建工具,如browserify ,或的WebPack ,您可以编写的脚本require节点模块和构建工具会生成一个脚本,包括所有必要的依赖(假设必要的依赖与客户端兼容JavaScript环境) 。

Downloading dependencies would still be done via npm , but only for local development. 下载依赖项仍将通过npm完成,但仅用于本地开发。 Your server would only need the generated script. 您的服务器只需要生成的脚本。

Alternatively, if the script is on github or any other repo online you may be able to download it directly. 另外,如果脚本在github或任何其他在线仓库上,则可以直接下载。 Many modules are published using UMD , which would allow you to use the script using various inclusion methods. 使用UMD发布了许多模块,这将允许您使用各种包含方法来使用脚本。

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

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