From bf70097688e4c062683d31c9f58399aee6747a49 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Wed, 5 Aug 2020 10:22:00 -0600 Subject: [PATCH] Adding example usage of the nodejs loader. Resolves #16. (#17) --- systemjs-features/nodejs-loader/README.md | 11 +++++++++++ systemjs-features/nodejs-loader/antarctica.js | 5 +++++ systemjs-features/nodejs-loader/index.html | 14 ++++++++++++++ systemjs-features/nodejs-loader/index.js | 17 +++++++++++++++++ systemjs-features/nodejs-loader/package.json | 14 ++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 systemjs-features/nodejs-loader/README.md create mode 100644 systemjs-features/nodejs-loader/antarctica.js create mode 100644 systemjs-features/nodejs-loader/index.html create mode 100644 systemjs-features/nodejs-loader/index.js create mode 100644 systemjs-features/nodejs-loader/package.json diff --git a/systemjs-features/nodejs-loader/README.md b/systemjs-features/nodejs-loader/README.md new file mode 100644 index 0000000..151aafb --- /dev/null +++ b/systemjs-features/nodejs-loader/README.md @@ -0,0 +1,11 @@ +# SystemJS nodejs example + +This example shows SystemJS running in the browser. + +## Running locally + +``` +cd nodejs-loader +npm install +npm start +``` \ No newline at end of file diff --git a/systemjs-features/nodejs-loader/antarctica.js b/systemjs-features/nodejs-loader/antarctica.js new file mode 100644 index 0000000..682b0aa --- /dev/null +++ b/systemjs-features/nodejs-loader/antarctica.js @@ -0,0 +1,5 @@ +System.register([], (_export) => ({ + execute() { + _export('default', "Antarctica is the southern continent"); + } +})); \ No newline at end of file diff --git a/systemjs-features/nodejs-loader/index.html b/systemjs-features/nodejs-loader/index.html new file mode 100644 index 0000000..ad34032 --- /dev/null +++ b/systemjs-features/nodejs-loader/index.html @@ -0,0 +1,14 @@ + + + + + + SystemJS NodeJS extra + + +

NodeJS extra

+

+ 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 github repository for more details. +

+ + \ No newline at end of file diff --git a/systemjs-features/nodejs-loader/index.js b/systemjs-features/nodejs-loader/index.js new file mode 100644 index 0000000..d645193 --- /dev/null +++ b/systemjs-features/nodejs-loader/index.js @@ -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); +}); \ No newline at end of file diff --git a/systemjs-features/nodejs-loader/package.json b/systemjs-features/nodejs-loader/package.json new file mode 100644 index 0000000..0ff5ea0 --- /dev/null +++ b/systemjs-features/nodejs-loader/package.json @@ -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" + } +}