Skip to content

NPM pkg for dist bundles #2670

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

Merged
merged 13 commits into from
Jul 5, 2018
Merged

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented May 25, 2018

resolves #2400

A new sync_pacakges.js script assembles "sub plotly.js packages" in the git-ignored build/ folder that include a minimal package.json and README.md as well as one single "bundle" file. Along with the main dist/plotly.js bundle, each partial bundle has it own "sub plotly.js package".

After running, node tasks/sync_pacakges.js, we get:

image

A sample package.json looks like:

image

and a sample README.md looks like:

image

Some questions left to answer:

  • Should we add the minified bundles to each sub package? Answer: no.
  • Should we add dist/topojson/ to all sub packages?
  • What to do with dist/extras/mathjax/? Should we include it too?

@nicolaskruchten what do you think?

etpinard added 2 commits May 25, 2018 16:54
- these sub-pkg are made in build/
- they all include a (minimal) README and package.json
- at the moment, they include only one un-minified bundle file
@etpinard
Copy link
Contributor Author

etpinard commented May 25, 2018

TODO:

  • we'll need to patch tasks/stats.js to make dist/README.md know about these npm "sub" packages
  • patch up the root README too.
  • update dev-docs about new npm publish behavior

@etpinard etpinard added this to the v1.39.0 milestone May 25, 2018
@nicolaskruchten
Copy link
Contributor

IMO no need to add minified versions. The main advantage I see for these packages is for people to import plotly.js in a more friendly way into their build systems like webpack and friends. In my experience, it's unhelpful to load minified files into such systems as it messes with their downstream minification.

@nicolaskruchten
Copy link
Contributor

More generally I'm a huge fan of this PR :)

@alexcjohnson
Copy link
Collaborator

Slick! As to the questions about topojson and MathJax - these are both outside of the build, so seems to me the question is what would be the most useful thing we could do for folks who want to use local versions of topojson and MathJax, that wouldn't inconvenience folks content to use the CDN versions of these (or ignore them entirely)? Feels to me like we may want to include topojson anyway since otherwise they'd have to include the full plotly.js anyway just to get that, right? But maybe not MathJax, which they can get from npm now.

Incidentally, I was just chatting with @etpinard about our 4-year-old mathjax version - we're using 2.3, they're up to 2.7.4. Presumably a drop-in replacement since it's still 2.x, though we may change how we package it due to the npm package. We could make a separate issue for this, but perhaps the upgrade should be this PR, regardless of whether it's going to be included in the dist packages or not... if it is included people may start to wonder why it's so old, if not they'll be including the current version anyway (or at least one they can get from npm, which started at 2.5.1) so we'd better make sure it works!

@etpinard
Copy link
Contributor Author

etpinard commented May 29, 2018

Feels to me like we may want to include topojson anyway since otherwise they'd have to include the full plotly.js anyway just to get that, right?

We could alternatively add a plotly.js-topojson npm package.

@cpsievert
Copy link

I would vote in favor of minified bundles if it's not too much overhead. It'd be much easier for me to leverage partial bundles in the R package that way.

@nicolaskruchten
Copy link
Contributor

(no objections to minified bundles if it's helpful for the R world!)

@etpinard
Copy link
Contributor Author

Just curious @cpsievert, why would an npm package be easier for you than downloading the min.js file from https://cdn.plot.ly/plotly-latest.min.js ?

@cpsievert
Copy link

cpsievert commented May 29, 2018

@etpinard do we publish minified partials to the cdn (e.g., https://cdn.plot.ly/plotly-basic.min.js doesn't exist)?

I don't currently leverage partial builds in R, and I could do it via github releases, but it'd be nice to have a lighter-weight approach. I also recently created this R package to make it easy to leverage unpkg from R https://github.com/cpsievert/runpkg

@etpinard
Copy link
Contributor Author

do we publish minified partials to the cdn (e.g., https://cdn.plot.ly/plotly-basic.min.js doesn't exist)?

yes -> https://cdn.plot.ly/plotly-basic-latest.min.js or https://cdn.plot.ly/plotly-basic-1.38.1.min.js

@etpinard
Copy link
Contributor Author

etpinard commented May 29, 2018

All you want to know about partial bundles is here -> https://github.com/plotly/plotly.js/tree/master/dist#plotlyjs-basic

@cpsievert
Copy link

cpsievert commented May 29, 2018

Ahhh, ok, I'll use the CDN then, sorry for the noise!

etpinard added 5 commits May 30, 2018 10:09
- factor up findModuleList from stats.js, to list which
  trace modules are included
- fixup cb when build/* exist
- add DRYRUN env var, to skip `npm publish`
... and refactor "Quick start options" section. List CDN first,
  plotly.js-dist 2nd and github release 3rd
etpinard added a commit to etpinard/plotly.js that referenced this pull request May 30, 2018
@etpinard
Copy link
Contributor Author

etpinard commented May 30, 2018

Reviewers, if you'll like to see what tasks/stats.js and tasks/sync_packages.js output, I made https://github.com/etpinard/plotly.js/tree/npm-pkgs-for-dist-bundles-build, where you can review:

BUILDING.md Outdated
@@ -1,5 +1,7 @@
# Building plotly.js

The easiest way to bundle plotly.js into your application is to use the one of the distributed plotly.js packages on npm. These distributed packages should just work with **any** build framework. That said, if you're looking to save a few bytes, read the section below corresponding to your building framework.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the one of the distributed...

Do you want to include a link that points to a list of these modules on npm? I guess we can add that later once it actually exists ;)

README.md Outdated

#### Install with `npm`

```bash
npm install plotly.js
npm install plotly.js-dist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please move this up above the CDN option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, using the CDN is still the "quickest" way to start using plotly.js (hence its first spot in the "Quick start options" section), but ok.

README.md Outdated

If you would like to manually pick which plotly.js modules to include, you can create a *custom* bundle by using `plotly.js/lib/core`, and loading only the trace types that you need (e.g. `pie` or `choropleth`). The recommended way to do this is by creating a *bundling file*:
If you would like to manually pick which plotly.js modules to include, you'll first need to run `npm install plotly.js` and then create a *custom* bundle by using `plotly.js/lib/core`, and loading only the trace types that you need (e.g. `pie` or `choropleth`). The recommended way to do this is by creating a *bundling file*. For example, in CommonJS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might prefix this with something like "If none of the distributed NPM packages meet your needs, and you would like to..." to encourage people to go with the flow :)

Copy link
Contributor Author

@etpinard etpinard May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should encourage people that want to save bytes to save bytes, but ok.

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented May 30, 2018

What will the NPM module page look like for these new modules? they'll just inherit the same readme, github URL and homepage URL as the main module right? so basically the npmjs.org pages will look the same as the current one except for the callouts here?

image

@etpinard
Copy link
Contributor Author

What will the NPM module page look like for these new modules?

Like their READMEs e.g.:

https://github.com/etpinard/plotly.js/blob/npm-pkgs-for-dist-bundles-build/build/plotly.js-cartesian-dist/README.md

@nicolaskruchten
Copy link
Contributor

Re the README how are you telling NPM that it should use that readme instead of the main one? AFAIK it just grabs the readme from the repository field in package.json .. ?

@etpinard
Copy link
Contributor Author

AFAIK it just grabs the readme from the repository field in package.json .. ?

Oh really? I thought it grabbed the package.json from where we run npm publish. Let me double-check.

@etpinard
Copy link
Contributor Author

Thanks for bringing this up @nicolaskruchten !

We have to list the files manually in this case, like react's mono-repo does e.g. for react-dom.

@josemarluedke
Copy link

Are there any plans to get this merged in and released?

@alexcjohnson
Copy link
Collaborator

Are there any plans to get this merged in and released?

Yes, it's ready to go but because it will result in substantial changes to the documentation we want to merge it immediately before releasing v1.39.0. That should happen within the next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPM modules for dists
5 participants