简体   繁体   English

如何在浏览器中加载NPM模块?

[英]How do I load NPM modules in the browser?

I want to use redux-thunk client-side (in browser) but the only implementation I find is an NPM module. 我想使用redux-thunk客户端(在浏览器中),但是我发现的唯一实现是NPM模块。 How can I load an NPM module in a browser? 如何在浏览器中加载NPM模块? What is the correct way? 正确的方法是什么? Webpack to bundle? 要打包的Webpack?

I ended up using Webpack. 我最终使用了Webpack。

If you want to use this library in for demo purposes, or some examples, you can get it from wzrd.in: https://wzrd.in/standalone/redux-thunk@latest 如果您想将此库用于演示目的或一些示例,可以从wzrd.in获取它: https ://wzrd.in/standalone/redux-thunk@latest

This website is browserify-as-a-service, that can build and return you any module from npm. 该网站是浏览器即服务,可以从npm构建并返回任何模块。

But be aware, this thing should not be used in production, because it is not intended as a highload solution. 但是请注意,该产品不应在生产中使用,因为它不打算用作高负载解决方案。 For that case you need to prepare a build with some tools, like Webpack or Browserify on your local machine. 对于这种情况,您需要在本地计算机上使用某些工具(例如Webpack或Browserify)准备构建。

使用webpack将是最好的选择,尤其是当您正在构建React应用并且正在使用webpack进行React时

Webpack or Browserify will both work fine. Webpack或Browserify都可以正常工作。

  • WebPack is newer and makes slightly smaller modules WebPack较新,并且使模块稍小

  • Browserify has been around longer and has more users. Browserify出现的时间更长,拥有更多的用户。

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

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