generator-express
generator-express copied to clipboard
Add ES6 support
Option for all code to follow ES6 syntax, use a flag e.g. --es6 until it's more supported
@petecoop Here we are some 7 months from this feature. Seems now would be a great time to make that happen seeing as we all should move towards ES2015 before ES2016 arrives :-)
Again, if you are open to PRs I could help with this as well
+1 for this
+1
+1
I happened to be looking into this tonight a bit to see how difficult it would be out of curiosity. I need to test this out a bit, but just looking around it seems like implementing this package https://www.npmjs.com/package/express-babelify-middleware similar to how the Coffeescript functionality is implemented might be the way to go.
I'm down to tackle this and see if I can get it but it might not be fast. It probably won't be until after talking about my PR #191 for moving from Jade to Pug if there are any issues with it.
That middleware is for converting front-end files on the fly. Similar to coffeescript would be using the babel-register require hook. However Node v6 already supports 91% of ES6 by default so it's just a case of changing the syntax within the templates a bit
Oh, gotcha. I misunderstood that. That makes sense, though. I wasn't sure what Node's capability was yet for ES6. Are all of the components that the generator uses compatible with Node 6 yet so we wouldn't have to worry?
Yep I'm running some projects with Node 6 with no issues, it's backward compatibility is pretty good
Since Node 8 should be out this spring (going on the LTS versions being released in October), does this still need to be a flag or are there enough people on Node 6+ that the code can just be updated to be ES2015+ syntax?
Yeah that's very true. The question is then what should I actually change, any suggestions?
I'll have to look this weekend. One place I can think of off the top of my head is in the express.js file where there are a bunch of var statements at the top to combine them down into one const statement (or a const and let statement if some need to mutate).
const express = require('express'),
glob = require('glob'),
favicon = require('serve-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
compress = require('compression'),
methodOverride = require('method-override');<% if(options.viewEngine == 'swig'){ %>
swig = require('swig');<% } %><% if(options.viewEngine == 'handlebars'){ %>
exphbs = require('express-handlebars');<% } %><% if(options.viewEngine == 'nunjucks'){ %>
nunjucks = require('nunjucks');<% } %>
And maybe in the MVC structure change some of the example models into classes if possible.
That is just quick off the top of my head. I haven't looked at the code in a while so some of that might not make sense and there might be some other areas to look into. Hopefully I can get some time this weekend to take a look.
I came down with a nasty cold and have been sleeping a lot. Hopefully I can get some time soon to look. Sorry for the delay in providing more insight :(
Hey no worries! I'll start an es6 branch for this