Skip to content
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

Provide a method to quickly register all imports in ESM builds #8425

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/docs/getting-started/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ Chart.register(
var myChart = new Chart(ctx, {...});
```

A short registration format is also available to quickly register everything.

```javascript
import { Chart, registerables } from 'chart.js';
Chart.register(...registerables);
etimberg marked this conversation as resolved.
Show resolved Hide resolved
```

## Require JS

**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.).
Expand Down
19 changes: 19 additions & 0 deletions src/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,22 @@ export * from './elements';
export * from './platform';
export * from './plugins';
export * from './scales';

import * as controllers from './controllers';
import * as elements from './elements';
import * as plugins from './plugins';
import * as scales from './scales';

export {
controllers,
elements,
plugins,
scales,
};

export const registerables = [
simonbrunel marked this conversation as resolved.
Show resolved Hide resolved
controllers,
elements,
plugins,
scales,
];
2 changes: 2 additions & 0 deletions types/index.esm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ export declare class Chart<
static unregister(...items: ChartComponentLike[]): void;
}

export const registerables: readonly ChartComponentLike[];

export declare type ChartItem =
| string
| CanvasRenderingContext2D
Expand Down