Skip to content

Make `require` work in browsers, at runtime. No code bundling needed!

Notifications You must be signed in to change notification settings

chenglou/require-polyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Require Polyfill

This simple script is inspired by require1k, with a few flaws fixed (works with npm3, reads package.json's main field, etc.).

Usage

Drop it into a script tag like so:

<script src="./path/to/require_polyfill.js" data-main="./path/to/entry/file" data-project-root="./"></script>

Where data-project-root is where node_modules is located.

Tada! All your js files' require statements will work! No watcher, no code bundling, no hassle.

Note: This is only meant to be used as a development time convenience.

Note2: On browsers like Chrome that disallow cross origin requests, we can't load directly from the file system. Start a local server in that case. Alternatively, try Safari or Firefox!

Known Issues

  • Doesn't polyfill the node.js libraries. So e.g. require('fs') would fail.

  • Doesn't support code splitting. Kidding, it supports all the code splitting.

  • Doesn't have a logo (TODO: create an entire community around this script).

About

Make `require` work in browsers, at runtime. No code bundling needed!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published