Skip to content

Commit 4b43d5c

Browse files
committed
Provide a method to quickly register all imports in ESM builds
1 parent 6de5b3f commit 4b43d5c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

docs/docs/getting-started/integration.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ Chart.register(
8080
var myChart = new Chart(ctx, {...});
8181
```
8282

83+
A short registration format is also available to quickly register everything.
84+
85+
```javascript
86+
import { Chart, registerables } from 'chart.js';
87+
Chart.register(...registerables);
88+
```
89+
8390
## Require JS
8491

8592
**Important:** RequireJS [can **not** load CommonJS module as is](https://requirejs.org/docs/commonjs.html#intro), so be sure to require one of the UMD builds instead (i.e. `dist/chart.js`, `dist/chart.min.js`, etc.).

src/index.esm.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,22 @@ export * from './elements';
44
export * from './platform';
55
export * from './plugins';
66
export * from './scales';
7+
8+
import * as controllers from './controllers';
9+
import * as elements from './elements';
10+
import * as plugins from './plugins';
11+
import * as scales from './scales';
12+
13+
export {
14+
controllers,
15+
elements,
16+
plugins,
17+
scales,
18+
};
19+
20+
export const registerables = [
21+
controllers,
22+
elements,
23+
plugins,
24+
scales,
25+
];

types/index.esm.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ export declare class Chart<
497497
static unregister(...items: ChartComponentLike[]): void;
498498
}
499499

500+
export const registerables: readonly ChartComponentLike[];
501+
500502
export declare type ChartItem =
501503
| string
502504
| CanvasRenderingContext2D

0 commit comments

Comments
 (0)