npm-require

synchronous global require function for the browser to load commonjs modules from a (relative) path, a URL or npm

Usage no npm install needed!

<script type="module">
  import npmRequire from 'https://cdn.skypack.dev/npm-require';
</script>

README

npm-require

synchronous global require function for the browser to load commonjs modules from a (relative) path, a URL or npm

https://www.npmjs.com/package/npm-require

demo

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="src/npm-require.js"></script>
  </head>
  <body>
    <script>
      var minixhr = require('minixhr') // from npm
      var pkg = require('./package.json')
      var demo = require('./demo') // resolves to `./demo.js`
      demo(pkg)
    </script>
  </body>
</html>

license

MIT