Synchronous require using es6 imports.
- Allows for "require" while being synchronous. This matches how common js works in Node.js.
- polyfilling module.exports and exports.
- Uses es6 imports so can be used in non-built modern and no combining of import and require allowed environments.
- Works on various URL formats: node_modules named, relative.
npm install @theopenweb/import-require-js
// import require from "./index.js" // import require from 'node_modules/@theopenweb/import-require-js/index.js' import require from '@theopenweb/import-require-js'
npx http-server ./ # Go to http://localhost:8080
Other libraries, etc
Requirejs is often used for implementing common js require functionality in browsers. However, it is "async" only: Requirejs is async. Synchronous handling only works on already loaded modules.
Synchronous handling can be handled as shown in that link. This is similar to how it is implemented in this library.
This library has only been made to support what is needed. There are some features that should be added but has not been yet. If you find something that should be added, please create a detailed issue.
Areas that could be impoved:
- Allowing for async handling, especially in nested libraries.
- Support for other library URL resolution(bower_component, etc.), local files, etc.
- Not include dependencies? Currently mustache(used for example) and require(might become needed).