Created
December 12, 2016 02:36
-
-
Save bitgord/245535acdfb39f489913c1cf3e6fe6af to your computer and use it in GitHub Desktop.
Quick setup to use ES6 with Heroku
This file contains hidden or 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
// First download node, create new folder | |
// Cd into new folder, npm and git init | |
// Create heroku app | |
heroku create | |
// install babel cli (to do compiling), babel presets (to compile the right features), express (web server) | |
npm install babel-cli babel-presets-es2015 express | |
// Create file .babelrs and add json | |
{ | |
"presets": ["es2015"] | |
} | |
// Create app folder with files app.js and greeter.js and require dependencies | |
// Add code to app.js | |
var express = require('express'); | |
var app = express(); | |
var greeter = require('./greeter.js'); | |
app.get('/', function (req, res) { | |
res.send(greeter()); | |
}); | |
app.listen(process.env.PORT || 3000); | |
// Add code to greeter.js | |
function greeter (msg = 'this works') { | |
return msg; | |
}; | |
// Export greeter | |
module.exports = greeter; | |
// From terminal run command // It compiles code beforehand so it doesnt save in memory (and slow down app) | |
babel app/*.js -d dist // Moves all files in app folder into a dist file // In dist babel compiles the code to be compatible with heroku // Do not update this file | |
// Tell Heroku how to start application in package.json | |
"start": "node ./dist/app/app.js" | |
// Tell Heroku how to build application in package.json | |
"build": "babel app/*.js -d dist" | |
// Run from terminal | |
npm run build | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good stuff, couple typos: line 8 should read
babel-preset-es2015
and line 10 should be.babelrc
file