https://github.com/charto/cresolve
Node-style module resolution for SystemJS
https://github.com/charto/cresolve
Last synced: 9 months ago
JSON representation
Node-style module resolution for SystemJS
- Host: GitHub
- URL: https://github.com/charto/cresolve
- Owner: charto
- License: mit
- Created: 2018-05-16T18:36:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-19T03:40:46.000Z (about 7 years ago)
- Last Synced: 2025-03-15T22:08:19.895Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cresolve
This library hooks SystemJS `resolve` to extend it with Node.js module resolution.
It also looks in [UNPKG](https://unpkg.com/) to load packages without installing them.
Custom SystemJS configuration is automatically generated in the browser.
Saving it to a file allows vanilla SystemJS to load the project,
so this library is only needed in development.
It solves pretty much all SystemJS configuration issues.
## Features
- Works in the browser, using `XMLHttpRequest` instead of native file IO.
- Looks for `node_modules` and inside, in the same places Node.js would.
- Automatic [UNPKG](https://unpkg.com/) fallback when package is not yet installed.
- Handles `browser` mappings in `package.json` files.
- Allows importing a directory when it contains `index.js`.
- Transpiles ES6 using TypeScript compiler (by default).
- Automatically tries `.tsx` if a file with `.ts` extension is missing.
- Generates SystemJS configuration JSON to easily eliminate dependency on this library and switch to vanilla SystemJS.
## Usage
First load a Promise polyfill (if needed), SystemJS and the SystemJS -format bundle provided under
[`dist/index-system.js`](https://unpkg.com/cresolve@1/dist/index-system.js) for example using `` tags.
Then import the resolver and patch SystemJS as follows:
```TypeScript
System.import('cresolve').then(function(cresolve) {
const resolver = new cresolve.Resolver(
cresolve.ifExists,
cresolve.fetch
);
resolver.patchSystem(System);
});
```
Afterwards, `System.import` and any `import` or `require` statements in imported code have Node.js module resolution superpowers.
To print the auto-generated configuration, use:
```TypeScript
console.log(JSON.stringify(resolver.systemConfig, null, '\t'));
```
# License
[The MIT License](https://raw.githubusercontent.com/charto/cresolve/master/LICENSE)
Copyright (c) 2018- BusFaster Ltd