简体   繁体   English

如何在节点模块上使用browserify?

[英]How to use browserify on node module?

I've try to browserify the module wcwidth 我尝试浏览器模块wcwidth

I've executed this code: 我执行了以下代码:

npm install wcwidth
npm install -g browserify
cd node_modules/wcwidth
browserify index.js -o wcwidth.js

it generated the file wcwidth.js but when I included the file in the html page I don't have access to wcwidth function, I've got error that wcwidth is undefined. 它生成了文件wcwidth.js但是当我在html页面中包含该文件时,我无权访问wcwidth函数,但出现了wcwidth未定义的错误。

What else I need to do in order to use node module in the browser? 为了在浏览器中使用节点模块,我还需要做什么?

I had to create a file: 我必须创建一个文件:

window.wcwidth = require('./');

save it in wcwidth.js and run: 将其保存在wcwidth.js并运行:

browserify wcwidth.js -o dist/wcwidth.js

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

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