Skip to content

Commit e50b063

Browse files
authored
Merge pull request #5702 from plotly/partial-bundles-readme
Revise partial bundle section in README
2 parents 79b4b3a + 6bf3974 commit e50b063

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

README.md

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,36 +70,54 @@ and use the plotly.js `dist` file(s). More info [here](https://github.com/plotly
7070

7171
#### Read the [Getting started page](https://plotly.com/javascript/getting-started/) for more examples.
7272

73-
## Modules
73+
## Partial bundles
7474

75-
Starting in `v1.15.0`, plotly.js ships with several _partial_ bundles (more info [here](https://github.com/plotly/plotly.js/blob/master/dist/README.md#partial-bundles)).
75+
There are two kinds of plotly.js partial bundles:
76+
1. The official partial bundles that are distributed to `npm` and the CDN, described in [the dist README](https://github.com/plotly/plotly.js/blob/master/dist/README.md).
77+
2. Custom bundles you can create yourself, if none of the distributed packages meet your needs.
7678

77-
Starting in `v1.39.0`, plotly.js publishes _distributed_ npm packages with no dependencies. For example, run `npm install plotly.js-geo-dist` and add `import Plotly from 'plotly.js-geo-dist';` to your code to start using the plotly.js geo package.
78-
79-
If none of the distributed npm packages meet your needs, and 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:
80-
81-
```javascript
82-
// in custom-plotly.js
83-
var Plotly = require('plotly.js/lib/core');
84-
85-
// Load in the trace types for pie, and choropleth
86-
Plotly.register([
87-
require('plotly.js/lib/pie'),
88-
require('plotly.js/lib/choropleth')
89-
]);
79+
Use the `traces` option to include just the trace types you need.
80+
```
81+
npm run partial-bundle -- --traces scatter,scattergl,scatter3d
82+
```
83+
Please note that the `scatter` trace is currently included in all bundles and cannot be removed.
84+
[This behaviour may change in the future](https://github.com/plotly/plotly.js/pull/5535), so we recommend that you explicitly include `scatter` anyway if you need it in your bundle.
9085

91-
module.exports = Plotly;
86+
By default all transforms are included in the bundle.
87+
Use the `transforms` option to specify which should be included.
88+
```
89+
npm run partial-bundle -- --transforms sort,filter
9290
```
9391

94-
Then elsewhere in your code:
92+
Or use `transforms none` to exclude them all.
93+
```
94+
npm run partial-bundle -- --transforms none
95+
```
9596

96-
```javascript
97-
var Plotly = require('./path/to/custom-plotly');
97+
Use the `out` option to change the bundle filename (default `custom`).
98+
The new bundle will be created in the `dist/` directory and named `plotly-<out>.min.js` or `plotly-<out>.js` if unminified.
99+
```
100+
npm run partial-bundle -- --out myBundleName
98101
```
99102

100-
Alternatively you could browserify a custom bundle of desired trace modules e.g. `pie` and `choropleth` using
101-
`npm run partial-bundle pie choropleth --name=custom`
103+
Use the `unminified` option to disable compression.
104+
```
105+
npm run partial-bundle -- --unminified
106+
```
102107

108+
### Example illustrating use of different options together
109+
To create an unminified custom bundle named `myScatters` including `scatter`, `scattergl` and `scatter3d` traces without any transforms:
110+
```
111+
npm run partial-bundle -- \
112+
--unminified \
113+
--out myScatters \
114+
--traces scatter,scattergl,scatter3d \
115+
--transforms none
116+
```
117+
Or simply on one line:
118+
```
119+
npm run partial-bundle -- --unminified --out myScatters --traces scatter,scattergl,scatter3d --transforms none
120+
```
103121

104122
## Building plotly.js
105123

0 commit comments

Comments
 (0)