Skip to content

Commit

Permalink
Adding import-map-scopes example. Resolves #14. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning authored Jun 4, 2020
1 parent 8d98f45 commit c3b0863
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions systemjs-features/import-map-scopes/dep-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
System.register([], function (_export) {
return {
execute: function() {
_export('version', 'v1');
}
};
});
7 changes: 7 additions & 0 deletions systemjs-features/import-map-scopes/dep-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
System.register([], function (_export) {
return {
execute: function() {
_export('version', 'v2');
}
};
});
44 changes: 44 additions & 0 deletions systemjs-features/import-map-scopes/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Import Map Scopes SystemJS Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="systemjs-importmap">
{
"imports": {
"main": "./main/main.js",
"dep": "./dep-v1.js"
},
"scopes": {
"./main/": {
"dep": "./dep-v2.js"
}
}
}
</script>
<!-- load SystemJS itself from CDN -->
<script src="https://cdn.jsdelivr.net/npm/systemjs/dist/system.js"></script>
<script>
System.import('main').then(main => {
console.log('main module was loaded', main);
});

System.import('dep').then(dep => {
console.log('dep, loaded as top level module', dep);
});

// prepareImport simply waits for all import maps to be processed
// You must do so before calling System.resolve()
System.prepareImport().then(function () {
System.import('dep', System.resolve('main')).then(dep => {
console.log('dep, loaded relative to main module', dep);
});
});
</script>
</head>
<body>
<h1>Check browser console for details</h1>
</body>
</html>
15 changes: 15 additions & 0 deletions systemjs-features/import-map-scopes/main/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
System.register(['dep'], function (_export) {
let dep;

return {
setters: [
function (ns) {
dep = ns;
}
],
execute: function () {
console.log('main is executing. dep version is', dep.version);
_export('default', 'main');
}
}
})

0 comments on commit c3b0863

Please sign in to comment.