Bundle using Rollup#359
Conversation
|
So please let me know if this is something this project is interested in and I'll polish up my PR. |
|
If the filesize differences are accurate I would love for this to be polished ... Reduced file size is crucial. |
|
I'll have some questions once I have time to digest the info, but definitely excited and interested in this. Thanks!! |
|
So I just realized that the way that dependency Tether is distributed causes some issues with the dead tree shaking. My analysis can be found here. So that means that the final builds are slightly bigger. Worst case all of Tether is missing and that means +25kB so 138kB. Still a significant win 👍 I'll be looking more into that. I actually found the issue by having the tests run against the bundled version of Reactstrap. This is something that we might want to consider doing anyway as it means that we're confident that what we ship is correct, not just our source. (but out of scope for this PR) |
|
I did see that issue previously, someone had an issue with reactstrap and turned out to be an issue upstream with tether. Couple of things, I'm not 100% committed to tether because of it's size and how long it takes to get a response (I'm not so great at response times either :). Is it worth forking to reactstrap org or personal repo with the required rollup changes until it gets added by hubspot? Another thing to note, I'd like to move to popper.js so a temporary fork of tether doesn't seem so bad to me.
I've thought about this before, but couldn't find an example. Do you happen to have a link to a project that does this? |
|
I like the way you think. There already is a PR for Tether that does all the work we need (it just never got merged 😞 ): shipshapecode/tether#175. It's mergable so we should be able to get a fork going of the latest version pretty easily. An example of a project that tests against compiled output is SvelteJS: https://github.com/sveltejs/svelte/blob/master/test/helpers.js#L11-L15 |
|
Some more questions related to this PR:
And some questions for follow up PRs once this one gets merged: (you can ignore these if you don't have time)
|
|
|
|
@eddywashere wrote in #359 (comment)
Any update on this? At least I will have to point package.json at a forked Tether. But what about other things ? |
| UncontrolledDropdown, | ||
| UncontrolledNavDropdown, | ||
| UncontrolledTooltip, | ||
| UncontrolledPopover, |
There was a problem hiding this comment.
Removed because import didn't exist
| "lodash.omit": "^4.4.1", | ||
| "lodash.tonumber": "^4.0.3", | ||
| "tether": "^1.3.4" | ||
| "tether": "balloob/tether#7e0d48e4ac2162e251dc2b69d7c13e6c29a5667f" |
There was a problem hiding this comment.
This is to point at a tether build 1.3.4 that is using Browserify. Repo here.
We can fork it to the Reactstrap org if preferred.
|
This is awesome. We're using Rollup and Reactstrap for projects too, came to the same conclusion you did @balloob. Would love to help if there's more work that needs to be done, otherwise this PR has a huge +1 from me. |
|
No more work to be done, I think that this PR is all good to go 👍 |
|
@balloob Do you have more stats on file size changes now that this is complete? Before & after? Will this impact existing users importing this library using different programs - e.g. Webpack, Browserify, etc.? |
|
I have a list of all the benefits in the PR intro. |
|
Just to confirm ... the latest screenshot is with the last changes in the PR ... so we're dropping from ~110KB -> ~27KB for ES ? |
|
The latest screenshot is with gzip applied. Without gzip we're going from 295kB to 111kB. With gzip it's 70.4kB to 27kB. |
eddywashere
left a comment
There was a problem hiding this comment.
minor question, otherwise lgtm
| "version": "4.3.0", | ||
| "description": "React Bootstrap 4 components", | ||
| "main": "lib/index.js", | ||
| "main": "lib/reactstrap.cjs.js", |
There was a problem hiding this comment.
Just ran the build scripts, shouldn't these point to dist instead of lib?
There was a problem hiding this comment.
My bad, you're right.
|
Not to be merged yet, I am still doing some tests if the final builds work in other projects. (before this I only ran the tests and verified that those passed) |
|
If other people want to test in their projects, it's easy using Yarn.
Now your project will use the reactstrap folder where you ran |
|
It seems tether is still giving some issues 🤔 sigh. I am using the Tether build from the browserify build of Tether that I found. But it seems to not work 😢 |
|
I'm using that same Tether build, it's working for me. Let me pull your changes and compare. |
|
Sigh, never mind, I was stupid. Looks like we're all good. I still had build artifacts in the lib dir and didn't pull down the package.json pointing at dist. So I was testing it against an older broken build that was not using the right Tether dependency. |
|
If people are interested in what is taking up the space, a break down of the bundle can be found here: https://sourcemap-reactstrap-ynraqillzu.now.sh Tether broke the source map tool, so Generated this by doing the following:
|
|
I removed the UMD because somehow the node modules did not get included 🤔 Since it was an extra feature, I'll leave it out for now. |
|
@balloob thanks a ton for looking into this and pushing it through! I'll do a minor release soon to get it out. |
|
This is great, thanks @balloob - though should reactstrap be using a github hash as an 'official' release dep?:
|
|
I can fork to this org and do a npm release for it. |
|
That would be good idea @eddywashere. And @gthomas-appfolio, please comment on shipshapecode/tether#175 too, since this should be merged upstream. |
|
Published as |
|
Yeah, this broke the lib directory as well as the dist, basically all of the distribution are busted. |
|
Reactstrap no longer includes unminified versions. So what used to be @virgofx, can you elaborate your use case more. Which file did you used to include and how did you use that in your page? The lib directory (which is btw very inefficient to use) should have transpiled import/export to require. That's a bug. I'll put up a PR. |
|
@TheSharpieOne fix for lib dir containing import/export in #384 |
|
@balloob can you elaborate on how |
|
I think umd is needed in the dist directory. Thus was @vigrofx use case, using script tags to import from the cdn. The cjs file in the dist is probably not really a needed as the lib/index.js is where cjs imports should be getting the files from. |
|
@TheSharpieOne from the PR intro:
|
|
I'll have a PR to add back UMD shortly. (and it's another 15kB smaller 🥂 ) |
|
Thanks @balloob Yes ... use case was just a simple HTML doc test using say one react component... application is compiled with Webpack2 using external references to React + Reactstrap ... injected as follows: <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-with-addons.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
<script type="text/javascript" src="//unpkg.com/[email protected]/dist/reactstrap.min.js"></script>changing for 4.4.0: <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-with-addons.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
<!-- error in screenshot above -->
<script type="text/javascript" src="//unpkg.com/[email protected]/dist/reactstrap.es.js"></script> And then of course adding my custom bundle afterwards. The above error was when importing the |
|
Would loose mode help shrink the individual generated lib files and/or the dist/ files? |







Reactstrap currently bundles using Webpack and generates both a
libdir for individual imports and minified versions + source maps in thedistdir.The current bundled and minified version of ReactStrap is 295kB (70.4kB gzipped). The individual transpiled components are great to cherry pick what you need into your project. However because they are individually transpiled, each of them will contain the Babel helpers which adds up quickly when importing multiple components. For example the transpiled Button component consists for almost 50% of Babel helpers.
Both Webpack 2 and Rollup support tree shaking. However, this is only supported when the imported dependency uses the ES6
importandexportstatements instead of the CommonJSrequireandexports.This PR:
breaks current Webpack 1 buildsfixed)importandexportThis gives the following benefits:
package.jsondirectivesjsnext:mainandmoduleto point at the ES build to allow Webpack 2 and Rollup do their tree shaking when bundling Reactstrap.mainwill keep pointing at the CommonJS build for backwards compatibility.This is still experimental. Work left to be done:Upgrade to Webpack 2 if we want to keep using the dev server or remove completelyTesting the changes
To test that the Rollup build works, we can run the tests against the bundled and minified build. To do so, first point all the imports at the bundled version (tested on my mac):
After that, run tests as usual.
Breaking changes
None! 💃