Skip to content

🔧 🔨 An example on how to use node modules on browser instead of a nodejs environment. WARNING ‼️ not all node modules will work on browsers

Notifications You must be signed in to change notification settings

rookiemonkey/boilerplate-npm_on_browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  1. require the npm package the you need
const Buffer = require('buffer').Buffer
  1. Append the variable to the window object
global.window.Buffer = Buffer
  1. Install browserify as devDep
yarn add browserify -D
  1. Compile your main.js file using browserify
browserify main.js -o output.js
  1. use your output.js on your html
<script src="output.js" ></script>
  1. run it on live server and check the window object on console if your npm package is present (in this example, it is Buffer)

About

🔧 🔨 An example on how to use node modules on browser instead of a nodejs environment. WARNING ‼️ not all node modules will work on browsers

Topics

Resources

Stars

Watchers

Forks