Skip to content

Commit

Permalink
Adding example usage of the nodejs loader. Resolves #16. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning authored Aug 5, 2020
1 parent c3b0863 commit bf70097
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
11 changes: 11 additions & 0 deletions systemjs-features/nodejs-loader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SystemJS nodejs example

This example shows SystemJS running in the browser.

## Running locally

```
cd nodejs-loader
npm install
npm start
```
5 changes: 5 additions & 0 deletions systemjs-features/nodejs-loader/antarctica.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
System.register([], (_export) => ({
execute() {
_export('default', "Antarctica is the southern continent");
}
}));
14 changes: 14 additions & 0 deletions systemjs-features/nodejs-loader/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SystemJS NodeJS extra</title>
</head>
<body>
<h1>NodeJS extra</h1>
<p>
This project does not run in the browser, but in NodeJS. To run the project, clone this repository, run npm install, and run npm start. See README.md in the <a href="https://github.com/systemjs/systemjs-examples/tree/master/nodejs-loader/">github repository</a> for more details.
</p>
</body>
</html>
17 changes: 17 additions & 0 deletions systemjs-features/nodejs-loader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const url = require('url');
const { System, applyImportMap, setBaseUrl } = require('systemjs');

// Setting base URL is optional - the default is to use process.cwd()
// so the code here is redundant
const basePath = url.pathToFileURL(process.cwd()).href;
setBaseUrl(System, basePath);

applyImportMap(System, {
imports: {
"antarctica": "./antarctica.js"
}
});

System.import('antarctica').then(ns => {
console.log('antarctica module', ns);
});
14 changes: 14 additions & 0 deletions systemjs-features/nodejs-loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "nodejs-loader",
"version": "1.0.0",
"description": "This example shows SystemJS running in the browser.",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"systemjs": "latest"
}
}

0 comments on commit bf70097

Please sign in to comment.