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

Build using rollup #8

Merged
merged 3 commits into from
Jun 6, 2019
Merged

Conversation

perrin4869
Copy link
Contributor

(Better) alternative to #6
Builds 3 different modules, cjs, umd and esm.

@edoardo-bluframe
Copy link
Contributor

Hey @perrin4869 v busy lately!

Am gonna merge asap okay?? 😄

@perrin4869
Copy link
Contributor Author

@edoardo-bluframe no hurry, just a nice to have :)

@perrin4869
Copy link
Contributor Author

@edoardo-bluframe any updates?

.babelrc Show resolved Hide resolved
@@ -1,3 +1,3 @@
node_modules
lib/
dist/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep the name lib?

I actually really like it!

Is there a reason we are renaming to dist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... well, usually I'd use lib for files which were transpiled using babel (usually I'd do that for modules meant to run only with node), and dist to distribute bundles output by rollup (or webpack).
Of course I can still change it if you prefer.

@@ -2,27 +2,28 @@
"name": "react-router-scroll-top",
"description": "An easy scroll to top component based on the React Router Scroll Restoration Example",
"version": "0.1.0",
"main": "index.js",
"main": "dist/react-router-scroll-top.cjs.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

lib?

"build": "webpack",
"clean": "rm -fr lib/",
"build": "rollup -c",
"clean": "rm -fr dist/",
Copy link
Contributor

Choose a reason for hiding this comment

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

lib?

@@ -2,27 +2,28 @@
"name": "react-router-scroll-top",
"description": "An easy scroll to top component based on the React Router Scroll Restoration Example",
"version": "0.1.0",
"main": "index.js",
"main": "dist/react-router-scroll-top.cjs.js",
"module": "dist/react-router-scroll-top.esm.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

lib?

"prepublish": "yarn test && yarn run clean && yarn run build",
"test": "eslint src/ && flow && jest --silent"
},
"devDependencies": {
"babel-core": "^6.26.0",
"@babel/core": "^7.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Love the upgrade to Babel 7!

export default [{
external,
input,
output: { exports: "named", file: `dist/${pkg.name}.cjs.js`, format: "cjs" },
Copy link
Contributor

Choose a reason for hiding this comment

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

lib?

}, {
external,
input,
output: { file: `dist/${pkg.name}.esm.js`, format: "esm" },
Copy link
Contributor

Choose a reason for hiding this comment

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

lib?

}, {
external,
input,
output: { exports: "named", file: `dist/${pkg.name}.umd.js`, format: "umd", globals, name },
Copy link
Contributor

Choose a reason for hiding this comment

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

lib?

src/index.js Outdated
@@ -1,7 +1,7 @@
// @flow

import { type Element } from "react"
import ScrollToTop from "./ScrollToTop"
import ScrollToTop from "./ScrollToTop.jsx"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we just rename that file to ScrollToTop.js and leave this as import ScrolToTop from "./ScrollToTop"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is usually good practice to name files with jsx in them jsx. I'd rather introduce rollup-plugin-node-resolve and add jsx as an extension, if we want to remove the .jsx from the import.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't that the case till about 2 years ago and now we have all moved on to just .js and took it as a community-wide standard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah looked into it and you are right :)
I've always stuck with airbnb's styling guide and they still insist on using jsx as a file extension, but since then, the React developers did move away from it. Updated the PR to reflect this

@edoardo-bluframe
Copy link
Contributor

@edoardo-bluframe any updates?

Here is a PR review!

Enjoy okay?? 😄

@edoardo-bluframe
Copy link
Contributor

Oh and @perrin4869 can we target develop in this PR?

Copy link
Contributor Author

@perrin4869 perrin4869 left a comment

Choose a reason for hiding this comment

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

I'll change the target to development!

.babelrc Show resolved Hide resolved
@@ -1,3 +1,3 @@
node_modules
lib/
dist/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... well, usually I'd use lib for files which were transpiled using babel (usually I'd do that for modules meant to run only with node), and dist to distribute bundles output by rollup (or webpack).
Of course I can still change it if you prefer.

src/index.js Outdated
@@ -1,7 +1,7 @@
// @flow

import { type Element } from "react"
import ScrollToTop from "./ScrollToTop"
import ScrollToTop from "./ScrollToTop.jsx"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is usually good practice to name files with jsx in them jsx. I'd rather introduce rollup-plugin-node-resolve and add jsx as an extension, if we want to remove the .jsx from the import.

@perrin4869 perrin4869 changed the base branch from master to develop March 9, 2019 19:35
@perrin4869
Copy link
Contributor Author

Maybe version 3 can be a react hook ;)

@perrin4869
Copy link
Contributor Author

rebased onto development

@perrin4869
Copy link
Contributor Author

Hm... I'm not very well acquainted with jest. Could you help me fix the test errors? Also, the next version should probably support react-router@5 and test against it

@edoardo-bluframe edoardo-bluframe merged commit a4a4f6d into bluframe:develop Jun 6, 2019
@edoardo-bluframe
Copy link
Contributor

@perrin4869 Hey I just tried the build from develop and it throws an error when I import it in my app

Can you check that it works when you import react-router-scroll-top as built with rollup?

@edoardo-bluframe
Copy link
Contributor

Invariant Violation: You should not use <Route> or withRouter() outside a <Router>

Are you able to try that and see that you get that error?

@edoardo-bluframe
Copy link
Contributor

Okay - just investigated

Our new version built with rollup works 100% with react-router@4 but it breaks with that error on react-router @5

The version built with webpack works 100% with both

Are you able to look into that @perrin4869 ?

@perrin4869
Copy link
Contributor Author

@edoardo-bluframe my guess would be multiple instances of react-router inside the same module.
Also we need to update the peerDependencies to support react-router@5.
Let me investigate it a bit further though, for now let's update the peer dependencies

@perrin4869
Copy link
Contributor Author

Also, rollup is producing 3 different builds: umd, esm and cjs... which one of the three are you using?

@edoardo-bluframe
Copy link
Contributor

Hey @perrin4869 I am just using import and it is defaulting to esm

Does that help?? 😄

@perrin4869
Copy link
Contributor Author

remix-run/react-router#6755
Probably relevant

@perrin4869 perrin4869 deleted the rollup branch June 11, 2019 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants