generator-express icon indicating copy to clipboard operation
generator-express copied to clipboard

Add ES6 support

Open petecoop opened this issue 10 years ago • 13 comments
trafficstars

Option for all code to follow ES6 syntax, use a flag e.g. --es6 until it's more supported

petecoop avatar Jun 06 '15 22:06 petecoop

@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

mikeerickson avatar Jan 30 '16 19:01 mikeerickson

+1 for this

breezewish avatar Feb 16 '16 03:02 breezewish

+1

kderbalah avatar Apr 26 '16 13:04 kderbalah

+1

willsteinmetz avatar Aug 19 '16 03:08 willsteinmetz

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.

willsteinmetz avatar Aug 19 '16 03:08 willsteinmetz

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

petecoop avatar Aug 19 '16 08:08 petecoop

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?

willsteinmetz avatar Aug 19 '16 12:08 willsteinmetz

Yep I'm running some projects with Node 6 with no issues, it's backward compatibility is pretty good

petecoop avatar Aug 19 '16 13:08 petecoop

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?

willsteinmetz avatar Jan 12 '17 20:01 willsteinmetz

Yeah that's very true. The question is then what should I actually change, any suggestions?

petecoop avatar Jan 13 '17 11:01 petecoop

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.

willsteinmetz avatar Jan 13 '17 19:01 willsteinmetz

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 :(

willsteinmetz avatar Jan 19 '17 04:01 willsteinmetz

Hey no worries! I'll start an es6 branch for this

petecoop avatar Jan 19 '17 10:01 petecoop