Skip to content

Commit

Permalink
Provide a method to quickly register all imports in ESM builds (#8425)
Browse files Browse the repository at this point in the history
  • Loading branch information
etimberg authored Feb 15, 2021
1 parent d26172a commit b036b7b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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);
```

## 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 = [
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

0 comments on commit b036b7b

Please sign in to comment.