-
-
Save davidwwu/bd616b7aa6cc7d7dab868ad29741ecab to your computer and use it in GitHub Desktop.
Quick setup to use ES6 with Heroku
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
// 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-preset-es2015 express | |
// Create file .babelrc and add json | |
{ | |
"presets": ["es2015"] | |
} | |
// Create app folder with files app.js and greeter.js and require dependencies | |
// Add code to app.js | |
import express from 'express'; | |
import greeter from './greeter.js'; | |
var app = express(); | |
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; | |
//add thiese lines in package.json | |
"scripts": { | |
// 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" | |
} | |
// From terminal run command | |
// It compiles code beforehand so it doesnt save in memory (and slow down app) | |
// Moves all files in app folder into a dist file | |
// In dist babel compiles the code to be compatible with heroku | |
// Do not update these files | |
npm run build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment