简体   繁体   中英

How to use browserify on node module?

I've try to browserify the module 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.

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:

browserify wcwidth.js -o dist/wcwidth.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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