Use npm package on client side

2019-02-12 14:53发布

is there a way I can use an npm package on the client side? For example, I want to use the dateformat(https://www.npmjs.com/package/dateformat) package in my client side javascript file

2条回答
Ridiculous、
2楼-- · 2019-02-12 15:26

Most of the packages on NPM are designed for server side and won't work on the client side because of security reasons. You could use NW.js, but the user would have to install your software on there computer.

"NW.js (previously known as node-webkit) lets you call all Node.js modules directly from DOM and enables a new way of writing applications with all Web technologies." http://nwjs.io/

查看更多
放荡不羁爱自由
3楼-- · 2019-02-12 15:32

If you want to use npm on the client you may consider using browserify which is designed for that purpose. The node module system is not compatible with browsers so browserify transpiles the javascript into something that will work. Hence the name : browserify.

查看更多
登录 后发表回答