dav
dav copied to clipboard
Modernize project
Hi! I've been doing some work in this repo in order to make it more pleasant to work with. Below is a quick overview of the changes I've done and their reasoning.
With all of these changes implemented, the project is more straightforward to work with, more modular, yields smaller sizes, has faster parsing times, and gives more efficient choices to developers using this library to suit their project.
As a sample, the minified browser version of the library, with all the dependencies bundled in, has gone from dav.min.js (129K) to dist/dav.browser.min.js (89K).
I understand this is a large, unsolicited PR, so it's ok if you don't want to implement some (or any) of these changes. Even if the changes to structure are not accepted, I think commits d6bbafc and f05e217 can be applied to the project as-is.
I'm happy to answer any questions or make any adjustments as needed.
- Updated a bit the project structure, storing the source modern js in
src, and the distributable files indist. While this is mainly a cosmetic change, it falls in line with the organization of most other npm packages. - Updated (almost) everything to use ES modules, as there were some holdover files. This enables the next optimization in this list. The
xmldomandxmlhttprequestrequires still exist because of their nature. - Use buble instead of babel, which is faster, more practical, and less complex; while fitting quite well to the modern js usage made in this project. This enables faster compiling and slightly less bytes used.
- Use rollup as a build tool, which creates a much smaller js bundle, and reduces parsing times in the browser. In Node.js, it reduces the time compounded by
requirecalls. It also enables other projects using this library to take advantage of ES modules and only take what they need from this library. - Use polyfills from
core-js, which makes them easily updated and more standards-compliant, instead of vendoring them in the repo. I also added thePromisepolyfill. - Use async functions instead of
co, which makes them easier to write, and can be compiled away withrollupandnodent. - Only include built code in
npm, as someone installing this library fromnpmdoesn't need the whole source code in both compiled and uncompiled source. - Update tests so they take advantage of everything listed here.
- Updated dependencies
What gets built in the dist folder is:
dav.jsfor regular Node.js usage, as well as usage with bundlers such as browserify and webpack. It has all the code of the library in a single file andrequirecalls for external modules.dav.es.jsfor ES-aware bundlers such as webpack 2 and rollup. It is identical todav.js, but using ES Modules instead of Common JS.dav.browser.jsfor including in the browser without a bundler (like a<script>tag), or with AMD loaders such asRequire.js. It has all the dependencies and polyfills bundled in the file.dav.browser.min.jsis the minified version ofdav.browser.js.- In the
dist_testfolder, a special version ofdav.jsgets built, which exposes some additional internal APIs to be used with the tests. However, it is not meant to be distributed. - All of these versions come with their
.mapfile to be efficiently debugged.
@cprecioso This is awesome! I'll try to find some time to review this weekend -- thanks!