dav icon indicating copy to clipboard operation
dav copied to clipboard

Modernize project

Open cprecioso opened this issue 7 years ago • 1 comments

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 in dist. 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 xmldom and xmlhttprequest requires 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 require calls. 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 the Promise polyfill.
  • Use async functions instead of co, which makes them easier to write, and can be compiled away with rollup and nodent.
  • Only include built code in npm, as someone installing this library from npm doesn'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.js for 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 and require calls for external modules.
  • dav.es.js for ES-aware bundlers such as webpack 2 and rollup. It is identical to dav.js, but using ES Modules instead of Common JS.
  • dav.browser.js for including in the browser without a bundler (like a <script> tag), or with AMD loaders such as Require.js. It has all the dependencies and polyfills bundled in the file.
  • dav.browser.min.js is the minified version of dav.browser.js.
  • In the dist_test folder, a special version of dav.js gets 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 .map file to be efficiently debugged.

cprecioso avatar Jan 05 '18 00:01 cprecioso

@cprecioso This is awesome! I'll try to find some time to review this weekend -- thanks!

lambdabaa avatar Jan 10 '18 01:01 lambdabaa