Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ES build to react-router and react-router-dom (#4425) #4432

Merged
merged 1 commit into from
Feb 3, 2017
Merged

Add ES build to react-router and react-router-dom (#4425) #4432

merged 1 commit into from
Feb 3, 2017

Conversation

billyjanitsch
Copy link
Contributor

This creates an ES build (still transpiled, but with ES2015 import/exports left in tact to enable tree-shaking) inside es/, updates the relevant gitignores & npm inclusions, and adds a "module" entry point to package.json of react-router and react-router-dom.

Please see #4425 (comment) before merging, as this also updates the react-router imports from react-router-dom to be top-level rather than cherry-picked (necessary to enable descendent tree-shaking). As-is, this increases the bundle size of cherry-picked CJS imports from react-router-dom, since they now include the entire react-router package.

IMO, this is fine -- if people care about bundle size, they should be using a tree-shaking bundler -- but if you disagree, I can add this babel plugin which would transpile the top-level imports back to cherry-picked ones during the CJS build.

@billyjanitsch billyjanitsch changed the title Add ES build to react-router and react-router-dom (#4425) Add ES build to react-router and react-router-dom [fixes #4425] Feb 1, 2017
@billyjanitsch billyjanitsch changed the title Add ES build to react-router and react-router-dom [fixes #4425] Add ES build to react-router and react-router-dom (#4425) Feb 1, 2017
@billyjanitsch
Copy link
Contributor Author

Any idea what's up with travis? The tests pass locally but the build stalls on CI.

@kwelch
Copy link
Contributor

kwelch commented Feb 1, 2017

See #4430 there were errors in a fix.

@billyjanitsch
Copy link
Contributor Author

Thanks @kwelch -- I'll wait for that to land and rebase onto it.

@timdorr
Copy link
Member

timdorr commented Feb 1, 2017

Landed that. Go nuts!

Copy link
Member

@timdorr timdorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nits.

@@ -23,12 +23,14 @@
"index.js",
"matchPath.js",
"withRouter.js",
"README.md",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why'd you remove the README? It gets added anyways, but it's also good to make it explicit, in case we want to switch tooling to yarn or something else that differs from npm's behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted. I figured it was safe to remove since there are other automatically-included files that aren't explicitly listed.

"scripts": {
"build-lib": "babel ./modules -d . --ignore __tests__",
"build-es": "BABEL_ENV=es babel modules -d es --ignore __tests__",
"build-lib": "babel modules -d . --ignore __tests__",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's ignored, I'd add a BABEL_ENV=cjs to basically label this script as the CommonJS one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@billyjanitsch
Copy link
Contributor Author

Rebased and addressed your comments. Any thoughts on #4432 (comment)?

@billyjanitsch
Copy link
Contributor Author

Travis is still sad; tests still passing locally :(

@timdorr
Copy link
Member

timdorr commented Feb 1, 2017

I dunno what was up with it. Maybe a BrowserStack issue?

In any case, I'm not sure about the need for the CJS transformation. Someone can just import from the react-router package to get around that, right?

@timdorr timdorr added the feature label Feb 1, 2017
@timdorr timdorr added this to the v4.0.0 milestone Feb 1, 2017
@billyjanitsch
Copy link
Contributor Author

Someone can just import from the react-router package to get around that, right?

For the simple re-exports, yes, but not for the DOM components that build on top of base ones like BrowserRouter. There won't be a way to import these in CJS without including the entire react-router package.

Copy link
Member

@mjackson mjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except for the re-exports.

@@ -1 +1 @@
export default from 'react-router/Prompt'
export { Prompt } from 'react-router'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you mean export { Prompt as default } from 'react-router'? Otherwise, people will have to import { Prompt } from 'react-router-dom/Prompt'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 😬

"umd"
],
"main": "index.js",
"module": "es/index.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is this line for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consumers of the ES build (webpack 2, rollup, etc.)

@mjackson mjackson merged commit f9369d8 into remix-run:v4 Feb 3, 2017
@mjackson
Copy link
Member

mjackson commented Feb 3, 2017

Awesome, thanks @billyjanitsch 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants