1

Looking at tables such as these: http://kangax.github.io/compat-table/es6/

It looks like Chrome is really close to supporting a lot of ES6, meaning (in my mind) that I should be able to drop the following during development:

var babelifyOptions = {
    presets: ['es2015', 'stage-0', 'react'],
    extensions: ['.js', '.jsx']
};

when using browserify:

browserify(browserifyOptions)
    .transform(babelify.configure(babelifyOptions))
    .bundle()
    .pipe(source('app.js'))
    .pipe(buffer())
    .pipe(gulp.dest('./dist/js'));

And with that hopefully speeding up build times. When building to production, obviously transpilation is still required.

However, when I drop out es2015 presets, browserify chokes on the build, not understanding things like .... This makes sense, but is it possible to run browserify while targeting Chrome only? (ie allowing token/operators/features that Chrome currently understands).

Chris
  • 54,599
  • 30
  • 149
  • 186

1 Answers1

1

I do not think browserify is the issue but your version of NodeJS is. I think NodeJS 6 was the first one to support a lot of the ES2015 features by default but notably it does not support the new ES module system. There are a few Babel presets that patch around the things that are missing. Here is just a list of the ones I found in a quick search:

Note: I've not used any of them so I cannot make a recommendation for you.

casr
  • 1,166
  • 2
  • 11
  • 17
  • The module part isn't a big issue, as chrome doesn't support it either. I'm running Node6.3.1 – Chris Oct 30 '16 at 12:00
  • What output do you get from the following? `node --version; echo "const letters = ['a', 'b', 'c']; console.log(...letters)" | node` – casr Oct 30 '16 at 12:02
  • Thanks for looking at this. I get the following: `v6.3.1 a b c` (across two lines) – Chris Oct 30 '16 at 12:14
  • 1
    I tried to make a minimal test case for you over at https://gist.github.com/casr/1800d30be83f77bef5e3a36c1ff78c21 . Try putting `package.json` and `index.js` into the same directory. The run `npm install && npm run build`. If it works you should see some `browserify`-style output in your terminal. You could try adjusting the versions of the libraries to see if that trips something up. – casr Oct 30 '16 at 12:24
  • Ah I see, so you still run babel, just without any presets/plugins. Testing now – Chris Oct 30 '16 at 12:34
  • Hmm, very interesting, I can run it without the -t babelify switch and it compiles. So something, somewhere is getting caught – Chris Oct 30 '16 at 12:44
  • `ParseError: 'import' and 'export' may appear only with 'sourceType: module'` Basically getting snagged on the import stuff. But, with these modifications I can get it running with, only the module plugin - which is the desired behaviour https://gist.github.com/cjke/f910b3a7132c58f786c80e6413079066 – Chris Oct 30 '16 at 13:06