<!DOCTYPEhtml><htmllang="en"><head> <metacharset="UTF-8"> <metaname="viewport"content="width=device-width, initial-scale=1.0"> <title>Document</title> <scripttype="module">// Wrap code in a function to prevent a top-level await. (async () => {// The next line raises a SyntaxError in intermediate browsers.const { helloWorld } =awaitimport('./helloWorld.js');// The next line in only executed if the browser supports// dynamic imports. It is never executed in intermediate browsers.helloWorld(); })(); </script></head><body></body></html>
System.register([],function (_export, _context) {return {execute:function () {document.body.appendChild(Object.assign(document.createElement('p'), { textContent:"Mercury is the planet nearest to the sun" }))/* The doAlert function is exported and can be used like this: System.import('mercury').then(mercuryModule => { mercuryModule.doAlert(); }) */_export('doAlert', doAlert);functiondoAlert() {alert("I hear it's quite warm on Mercury"); } } }})
System.register([],function (_export, _context) {return {execute:function() {document.body.appendChild(Object.assign(document.createElement('p'), { textContent:'Neptune is a planet that revolves around the Sun' }));// Dynamic import within a module calculates a url relative to the current module_context.import('./triton.js').then(function (triton) {console.log("Triton was discovered on",triton.discoveryDate); }); } };});
C:\Users\Administrator\Desktop\practice\triton.js
System.register([],function (_export, _context) {return {execute:function() {document.body.appendChild(Object.assign(document.createElement('p'), { textContent:'Triton is a moon that revolves around Neptune.' }));_export("discoveryDate","Oct. 10, 1846"); } };});
consturl=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 redundantconstbasePath=url.pathToFileURL(process.cwd()).href;setBaseUrl(System, basePath);applyImportMap(System, { imports: {"antarctica":"./antarctica.js" }});System.import('antarctica').then(ns => {console.log('antarctica module', ns);});
{"name":"nodejs-loader","version":"1.0.0","description":"This example shows SystemJS running in the browser.","main":"main.js","scripts": {"start":"node main.js" },"author":"","license":"ISC","dependencies": {"systemjs":"latest" }}
<!DOCTYPEhtml><htmllang="en-US"><head> <metacharset="utf-8"> <metahttp-equiv="X-UA-Compatible"content="IE=edge"> <title>AMD Dependencies - SystemJS Example</title> <metaname="viewport"content="width=device-width, initial-scale=1"> <scripttype="systemjs-importmap"> { "imports": { "titan": "./lib/titan.js", "rxjs": "//cdn.jsdelivr.net/npm/rxjs/bundles/rxjs.umd.min.js" } } </script> <scriptsrc="//cdn.jsdelivr.net/npm/systemjs/dist/system.js"></script> <scriptsrc="//cdn.jsdelivr.net/npm/systemjs/dist/extras/amd.js"></script><!-- The named-exports extra is important to avoid having to rxjs.default.of() (and similar for all other rxjs functions) --> <scriptsrc="//cdn.jsdelivr.net/npm/systemjs/dist/extras/named-exports.js"></script></head><body> <divid="react-container"></div> <script>System.import('titan') </script></body></html>
import { of, from } from'rxjs';of("Saturn").subscribe( planet => {document.body.appendChild(Object.assign(document.createElement('p'), {textContent:`Titan is a moon orbiting ${planet}.`} )) })consttitanFacts= ["Titan is 50% more massive than Earth's moon, and 80% more massive.","Titan is the only moon known to have a dense atmosphere, and the only known body in space, other than Earth, where clear evidence of stable bodies of surface liquid has been found."];from(titanFacts).subscribe( fact => {document.body.appendChild(Object.assign(document.createElement('p'), {textContent: fact} )) });
System.register(["rxjs"],function (_export, _context) {"use strict";var of, from, titanFacts;return { setters: [function (_rxjs) {of=_rxjs.of; from =_rxjs.from; }],execute:function () {of("Saturn").subscribe(planet => {document.body.appendChild(Object.assign(document.createElement('p'), { textContent:`Titan is a moon orbiting ${planet}.` })); }); titanFacts = ["Titan is 50% more massive than Earth's moon, and 80% more massive.","Titan is the only moon known to have a dense atmosphere, and the only known body in space, other than Earth, where clear evidence of stable bodies of surface liquid has been found."];from(titanFacts).subscribe(fact => {document.body.appendChild(Object.assign(document.createElement('p'), { textContent: fact })); }); } };});
constpath=require('path');const { CleanWebpackPlugin } =require('clean-webpack-plugin')module.exports= { entry:path.resolve(__dirname,'src/entry.js'), mode:'development', output: { filename:'bundle.js', path:path.resolve(__dirname,'dist'), libraryTarget:'system', }, devtool:'sourcemap', plugins: [newCleanWebpackPlugin()],// Webpack externals will be shared across bundles and come from the import map and systemjs externals: ['vue','vue-router'],};
import*as neptune from'./neptune.js'document.body.appendChild(Object.assign(document.createElement('p'), { textContent:"Saturn is 1,433,449,370 km from the Sun, on average." }));neptune.showDistanceFromSun();
exportfunctionshowDistanceFromSun() {document.body.appendChild(Object.assign(document.createElement('p'), { textContent:"Neptune is 4,503,443,661 km from the Sun, on average." } ));}
import React from'react';import ReactDOM from'react-dom';ReactDOM.render(<button>A button created by React</button>,document.getElementById('react-root'));
import _ from'lodash';import { isPlanet } from'./helpers/planet-helpers';import { RealPlanets, NotRealPlanets } from'./planets';document.body.appendChild(Object.assign(document.createElement('p'), { textContent:'Pluto is no longer considered a planet. (Check you console for more information).'}))/* In a browser console, you can use the isPlanet function with the following code: System.import('planet-checker').then(planetChecker => { const isPlanet = planetChecker.isPlanet('thing'); })*/// Planet operationsisPlanet(RealPlanets.Earth);isPlanet(NotRealPlanets.Pluto);// Just a demonstration that lodash is available, since the systemjs-importmap in index.html// specifies where to fetch lodashconsole.log('Real Planets');_.each(RealPlanets, planet =>console.log(planet));
(function () {constendsWithFileExtension= /\/?\.[a-zA-Z]{2,}$/;constoriginalResolve=System.constructor.prototype.resolve;System.constructor.prototype.resolve=function () {// apply original resolve to make sure importmaps are resolved firstconsturl=originalResolve.apply(this, arguments);// append .js file extension if url is missing a file extensionreturnendsWithFileExtension.test(url) ? url : url +".js"; };})();
document.body.appendChild(Object.assign(document.createElement('p'), { textContent:'Pluto is no longer considered a planet.'}))/* In a browser console, you can use the isPlanet function with the following code:System.import('planet-checker').then(planetChecker => { const isPlanet = planetChecker.isPlanet('thing');})*/exportfunctionisPlanet(planetName:InterstellarObjects) {if (RealPlanets[planetName]) {console.log(`${planetName} is a planet!`)returntrue } elseif (NotRealPlanets[planetName]) {console.log(`${planetName} is not a planet!`)returnfalse } else {throwError(`Unknown planetName ${planetName}`) }}typeInterstellarObjects=RealPlanets|NotRealPlanetsenumRealPlanets { Mercury ='Mercury', Venus ='Venus', Earth ='Earth', Mars ='Mars', Jupiter ='Jupiter', Saturn ='Saturn', Uranus ='Uranus', Neptune ='Neptune',}enumNotRealPlanets { Pluto ='Pluto',}isPlanet(RealPlanets.Earth)isPlanet(NotRealPlanets.Pluto)
document.body.appendChild(Object.assign(document.createElement('p'), { textContent:"Earth is a planet that revolves around the sun"}))/* To use the doAlert function, run the following in the browser console:System.import('earth').then(earthModule => { earthModule.doAlert();})*/exportfunctiondoAlert() {alert("Earth is home to billions of humans and other life forms.");}
import'./set-public-path'document.body.appendChild(Object.assign(document.createElement('div'), { textContent:"Are there aliens on Mars?" }))document.body.appendChild(Object.assign(document.createElement('button'), { textContent:"Click to find out", onclick: findAliens }))/* This function can be called with the following code:System.import('mars').then(marsModule => { marsModule.findAlens();})*/exportfunctionfindAliens() {import('./sentient-aliens.js')}