-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use UMD bundle and ES6 modules #1069
Conversation
@kamilkisiela is this PR intended for reference only? |
@helfer I was working on an example for So I ended up with these changes and I decided to open a PR and a discussion :) |
@kamilkisiela @Urigo this is a pretty major change, so it would have been very useful if you let me know beforehand so we could plan things and avoid wasting time by having to redo parts of this PR (or other PRs) after merging other stuff. It's also unfortunate that removing circular dependencies was rolled in with this PR, I think we could have merged it more quickly otherwise (no need to manually check that the Apollo Client package doesn't break). Other than that, I think this is pretty cool, so thanks for the hard work! It looks like tree-shaking doesn't actually do much for our library size, but it's always nice to support it. |
"typings": "./lib/src/index.d.ts", | ||
"scripts": { | ||
"dev": "./scripts/dev.sh", | ||
"deploy": "rm -rf ./lib && npm run compile && ./scripts/deploy.sh", | ||
"pretest": "npm run compile", | ||
"deploy": "rm -rf ./lib && ./scripts/deploy.sh", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the assumption here that the compiler and bundler already ran at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm run compile
is here, so there's no point of running it twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
Nicely done! |
@DxCx yeah, I understand that. At the same time it's surprising to see that tree shaking doesn't reduce the library size because I assumed that we had a lot of dependencies of which we only use a small part. I guess that means we were pretty good at only importing what we really needed. |
@kamilkisiela Can I bug you again when I think things are stable enough to merge this into the 0.6 branch? A lot of conflicts will need to be resolved, so I think it would make sense to do this in a relatively short timeframe once we're ready. |
@helfer Sure thing! 👍 |
@kamilkisiela do you have time to change the base of this PR to zero-decimal-six in the next day or two and fix all the conflicts? If you can, then I can merge it and release it with 0.6 :) |
@helfer Yep. There's an issue with code coverage reports, I'm working on it. |
@helfer Maybe we could update the |
Closes #746 |
Note: Typescript files with only types, are used only in compilation phase and not going to be imported on compiled javascript. Closes #1074
This way we avoid an issue with require('lodash/someFunction').default()
@helfer Okay, done. |
@kamilkisiela re updating redux: sure thing, feel free to update it to the latest (compatible) version! |
Hm, that's weird, it still says the base is master on github. edit: Oh, I see, you rebased, but you didn't change the base... |
@helfer Yes... Look now |
This way we avoid using @types/redux and we use official typescript definition instead
Thanks a lot @kamilkisiela, merging now! |
I'm trying to upgrade from 0.5.10 to 0.8.0 (as a sugestion from #1194) but I'm experiencing an unexpected token error. As far as I could investigate, importing apollo-client as Any thoughts? Posting here because it definitely seems related. EDIT: Ok, I found the issue: I'm importing ApolloError class to do some custom error normalization. The problem is on version 0.5.10 I could simply import doing This error normalization is not the only low-level api I'm using from Apollo... I hope I can find them through the officially exported bundle. |
UMD bundle for everyone and a version with ES6 modules for those who might be interested in tree-shaking etc.
@helfer We talked some time ago about the tree-shaking. I already moved
angular2-apollo
(released),apollo-client-rxjs
(not yet published) and created an example (will publish it later today).TODO:
Rollup
We use
rollup
to produce the UMD bundle that contains all files. This way we get smaller size of the library and support for CommonJS and AMD.ESM (ES6 Modules)
We compile TS files to ES5, so this stays the same. Only difference is that we use es6 modules instead of commonjs. Thanks to that change the
apollo-client
is tree-shaking friendlymain
andmodule
To make these changes to work with most of build tools we use
main
andmodule
fields ofpackage.json
:module
tells where to look for ES6 modules.main
the same as before, points to files with CommonJS (in this case, only one file)Filesize
Because we use
rollup
and we have everything inside just one file, size of the library has been reduced.Before:
The total size of index.min.js is 136 kB.
The total gzipped size of index.min.js is 35.7 kB.
After:
The total size of index.min.js is 127 kB.
The total gzipped size of index.min.js is 34.8 kB.
Tests
You probably noticed that I use
babel
to compile already compiled files.When TypeScript sees this:
It's being compiled to:
And since
lodash/isBoolean
looks like this:We end up with
isBoolean
asundefined
.This is why I use
babel
to compile ES5 file with ES6 modules to CommonJS somocha
could handle it.Deploy
I also applied these changes in
scripts/deploy.sh
.Circular Dependencies
We also fixed the issue #1074
After this PR we can merge these:
PS @Urigo I wrote a summary so everyone can easily follow changes etc