susielu/d3-annotation

The library is repacking d3 modules

Closed this issue · 6 comments

When including this library file directly, it comes with it's own version of d3 modules, duplicating the code when d3 lib is already on the page

Ah yes, what is your build setup?

I've had quite a few problems with rollup not packing up the module properly regarding dependencies. I am thinking of moving over to webpack.

I was not using any build setup, I was adding the file directly to the html page.

There's more than way to bundle the package for publishing, but I think the way d3 approaches the problem is quite reasonable.
If you pick as an example the d3-scale module, when you import it directly on the html page:

<script src="https://d3js.org/d3-scale.v1.min.js"></script>
or
<script src="https://unpkg.com/d3-scale@1"></script>

you need to also import each one of its dependencies.

If you use the d3-scale through npm and a package bundler you import it using import or require and it's own dependencies are solved through npm dependency resolution.

For both cases, the dependencies of d3-scale are not bundled together with the package code.
The opposite is happening with d3-annotation, the package bundled up the code of its dependencies, so when using it directly in a html or a node project together with another d3 import you get double the code of some of some of d3-modules.

If this makes sense to you, I can try to take a look into doing a PR for matching how d3-modules solve their dependencies.

Thanks for the full explanation, I am using a similar setup with rollup for some of the other packages for npm. I can try using it for the web version as well and see if I can get it working. I had some issues with it in the past. If I run into issues, will definitely take you up on your offer for a PR.

@LuisCarli would you mind taking a look at this branch https://github.com/susielu/d3-annotation/tree/new-build ? The d3-annotation files shouldn't be packaging the dependencies anymore but curious to hear if the new files work properly with your use cases. Was able to get all my examples to work.

Merged to master, closing this unless you find any issues @LuisCarli

Looks great, thanks!!