Last active
September 9, 2016 20:16
-
-
Save androide-osorio/6738daebb583a169715e3cd724f7d469 to your computer and use it in GitHub Desktop.
ES2015 Roadtrip to awesomeness: Modules and SystemJS - this is a great way to quickly test an idea without having to use Webpack or Browserify. DO NOT USE FOR PRODUCTION CODE!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with systemJS, you can import any npm module | |
// directly in the browser and use it as you see fit. | |
// just prepend the module name with 'npm:' | |
import { sum, kebabCase } from 'npm:lodash' | |
import { addTax } from './checkout'; | |
const amount = 1500; | |
const myName = 'Androide Osorio'; | |
console.log('Hi, my name is'); | |
console.log(`%c ${myName}`, 'font-size: 36px; color: #fe570f; text-transform: uppercase'); | |
console.log(`you can find me at: http://github.com/${kebabCase(myName)}`); | |
console.log('and I\'m the fucking boss! 😎'); | |
console.log(''); | |
console.log('Now that you\'ve seen this, pay for my time!'); | |
console.log(`My rate is USD $${amount} + taxes (30%),`); | |
console.log(`for a total of: %c USD $${addTax(amount, 0.3)}`, 'font-weight: bold; color: green'); | |
console.log('Thank you, bitch!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
EXAMPLE OF A LOCAL MODULE | |
*/ | |
/** | |
* calculate the tax to pay for an amount of money | |
* @param {number} amount a positive number | |
* @param {number} taxRate a relative tax rate (between 0 and 1) | |
*/ | |
export function addTax(amount, taxRate) { | |
return amount + (amount * taxRate); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ES6 modules using SystemJS</title> | |
</head> | |
<body> | |
<script src="https://jspm.io/system@0.19.js" charset="utf-8"></script> | |
<script type="text/javascript"> | |
// configure systemJS | |
System.config({ transpiler: 'babel' }); | |
// configure the initial app entry (where other modules will be imported) | |
System.import('./app.js'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
systemJS does not work with the
file://
protocol, so you can't test local files directly, hence you must use any type of HTTP server to load your content. For local development, use npm'shttp-server
orbrowser-sync
packages.