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 @@ + + +
+ + ++ 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" + } +}