react-router icon indicating copy to clipboard operation
react-router copied to clipboard

Strategy for using ES6

Open mjackson opened this issue 11 years ago • 5 comments

What is our strategy for introducing ES6 code into the core modules? It's easy to do it in tests and the global build because we run both of those through webpack. But we should make this work when people are using CommonJS require as well.

A few possible solutions:

  • Keep ES6 out of the core modules
  • Have a pre-publish script that compiles everything to ES5. People who use Github master (pro-style) need to be aware (AFAICT React does this)
  • Put something in the README to let everyone know that they need to handle this themselves, probably using something like 6to5 or node-jsx

Any other ideas?

mjackson avatar Feb 22 '15 20:02 mjackson

cc @ryanflorence @gaearon @taurose

mjackson avatar Feb 22 '15 20:02 mjackson

I'm against (3), this hurts users. (1) seems backwards.

(2) is what I do in react-dnd. Babel (ex 6to5) has CLI to compile whole directories, so that's what I do to preserve file structure for CommonJS. When cutting a release, I'll compile modules to dist-modules and set that as "main" entry point in package.json.

https://github.com/gaearon/react-dnd/blob/master/scripts/build

This worked well for me.

gaearon avatar Feb 22 '15 20:02 gaearon

I know I'm not on the react-router team, but whatever:

I think @gaearon has totally valid points. I recently had to do the same for a small lib (pre-transpile into a dist folder). The issue with having babel do its magic is, that - by default - it excludes every module that resides on node_modules. You can pass a regex to only ignore certain folders in there, but it's quite a hassle do it like this. And just passing ignore: false to force all modules to be transpiled is kind of not an option.

Having a pre-transpiled release seems to be the easiest thing to do. The cli to compile directories is super easy to use: babel srcdir --out-dir destdir.

Not having to worry about configuring babel correctly to include certain modules in the node_modules directory in the transpiliation step is something that I as a user would really appreciate.

If somebody wanted - for some reason - to use the non-transpiled code they could still so something similar to import Router from 'react-router/lib/Router'.

Just my two cents :)

johanneslumpe avatar Feb 23 '15 10:02 johanneslumpe

Mostly agree with what the others said.

  1. feels a bit rushed, at least until es6 is released and widely adopted. It might not be as bad if we only targeted the browser (people using commonjs for browser would need to use a precompilation step anyways).

  2. seems like the way go. As johanneslumpe suggested, I think we should offer a way to use the es6 version (eg require('react-router/es6')) to be able to drop unused imports (webpack/webpack/pull/683) for instance.

agundermann avatar Feb 23 '15 17:02 agundermann

I agree. (2) seems like the best option.

Related, I just ran into https://github.com/babel/babel/issues/756 ... eeesh.

mjackson avatar Feb 23 '15 17:02 mjackson