Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 93b1551

Browse files
committed
examples, readme
1 parent 5b3d699 commit 93b1551

File tree

6 files changed

+77
-8
lines changed

6 files changed

+77
-8
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
System Register Loader
2+
===
3+
4+
Only loads System.register modules, as described in https://github.com/ModuleLoader/es-module-loader/blob/master/docs/system-register.md.
5+
6+
Follows the WhatWG loader resolution algorithm, throwing when loading plain / bare names like "lodash".
7+
8+
Built with the ES Module Loader polyfill 1.0 branch at https://github.com/ModuleLoader/es-module-loader.
9+
10+
### Installation
11+
12+
```
13+
npm install system-register-loader
14+
```
15+
16+
### Browser Usage
17+
18+
```html
19+
<script src="dist/system-register-loader.js"></script>
20+
<script>
21+
var loader = new SystemRegisterLoader();
22+
23+
// relative path or URL syntax is necessary as plain resolution throws
24+
loader.import('./path/to/file.js').then(function(m) {
25+
// ...
26+
});
27+
</script>
28+
```
29+
30+
### Node Usage
31+
32+
```javascript
33+
var SystemRegisterLoader = require('system-register-loader');
34+
35+
var loader = new SystemRegisterLoader();
36+
37+
loader.import('./path').then(function(m) {
38+
// ...
39+
});
40+
```
41+
42+
LICENSE
43+
---
44+
45+
MIT

example/browser.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html>
2+
<script src="../dist/system-register-loader.js"></script>
3+
<script>
4+
var loader = new SystemRegisterLoader();
5+
loader.import('./register.js').then(function(m) {
6+
console.log(m);
7+
});
8+
</script>

example/node.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var SystemRegisterLoader = require('../dist/system-register-loader.js');
2+
3+
var loader = new SystemRegisterLoader(__filename);
4+
5+
loader.import('./register.js').then(function(m) {
6+
console.log(m);
7+
})
8+
.catch(function(err) {
9+
setTimeout(function() {
10+
throw err;
11+
});
12+
});

example/register.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
System.register([], function($__export) {
2+
return function() {
3+
$__export({
4+
hello: 'world'
5+
});
6+
};
7+
});

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"main": "system-register-loader.js",
66
"author": "Guy Bedford",
77
"license": "MIT",
8-
"scripts": {
9-
"build": "rollup -c"
10-
},
118
"devDependencies": {
129
"rollup": "^0.34.7",
1310
"rollup-plugin-node-resolve": "^2.0.0"
11+
},
12+
"scripts": {
13+
"build": "rollup -c",
14+
"prepublish": "rollup -c"
1415
}
1516
}

src/system-register-loader.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import RegisterLoader from 'es-module-loader/core/register-loader.js';
22
import { isBrowser, isNode, envGlobal as global, baseURI } from 'es-module-loader/core/common.js';
33
import { resolveUrlToParentIfNotPlain } from 'es-module-loader/core/resolve.js';
44
import { scriptLoad, nodeFetch } from 'es-module-loader/core/fetch.js';
5-
import { loadModuleScripts } from 'es-module-loader/core/module-scripts.js';
65

76
/*
87
* Example System Register loader
@@ -12,7 +11,7 @@ import { loadModuleScripts } from 'es-module-loader/core/module-scripts.js';
1211
* If the module does not call System.register, an error will be thrown
1312
*/
1413
function SystemRegisterLoader(baseKey) {
15-
baseKey = resolveUrlToParentIfNotPlain(baseKey, baseURI) || baseKey;
14+
baseKey = resolveUrlToParentIfNotPlain(baseKey || (isNode ? process.cwd() : '.'), baseURI) || baseKey;
1615
RegisterLoader.call(this, baseKey);
1716

1817
var loader = this;
@@ -22,9 +21,6 @@ function SystemRegisterLoader(baseKey) {
2221
global.System.register = function() {
2322
loader.register.apply(loader, arguments);
2423
};
25-
26-
// support <script type="module"> tag in browsers
27-
loadModuleScripts(this);
2824
}
2925
SystemRegisterLoader.prototype = Object.create(RegisterLoader.prototype);
3026

0 commit comments

Comments
 (0)