This page covers a next version of Handsontable, and is not published yet.

This page covers a non-latest version of Handsontable.

# Bundle size

Use modules and optimize Moment.js, to reduce Handsontable's bundle size.

# Use modules

To reduce the bundle size and JavaScript parsing time, import only those of Handsontable's modules that you actually use, instead of importing the complete package.

The following example shows how to import and register the ContextMenu plugin on top of the base module of Handsontable, without importing anything else.

import Handsontable from 'handsontable/base';
import { registerPlugin, ContextMenu } from 'handsontable/plugins';

registerPlugin(ContextMenu);

new Handsontable(container, {
  contextMenu: true,
});

# Optimize Moment.js

By default, Moment.js (opens new window) (Handsontable's dependency) comes with all possible locales, which increases the bundle size.

To optimize Moment.js locales (opens new window), use webpack's IgnorePlugin (opens new window):

const webpack = require('webpack');
module.exports = {
  //...
  plugins: [
    // ignore all Moment.js locale files
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  ],
};

And then explicitly load Moment.js, importing just those locales that you need:

import Handsontable from 'handsontable/base';
import { registerCellType, DateCellType } from 'handsontable/cellTypes';

// explicitly import Moment.js
import moment from 'moment';
// explicitly import a Moment.js locale of your choice
import 'moment/locale/ja';

// register the Moment.js locale of your choice
moment.locale('ja');
registerCellType(DateCellType);

new Handsontable(container, {
  type: 'date',
});