Installing plugins

    In this guide you can learn how to add plugins to your editor in the two most common scenarios:

    In order to start developing CKEditor 5 you will require:

    • Node.js 6.9.0+
    • npm 4+ (note: some npm 5+ versions were known to cause , especially with deduplicating packages; upgrade npm when in doubt)

    Adding plugins to existing builds is done through their customization. Editor builds are maintained in their respective GitHub repositories. Therefore, assuming that you want to customize the classic editor build you need to:

    • Clone the build repository.
    • Install the plugin package.
    • Add it to the build configuration.
    • Bundle the build.

    Now, install the plugin package:

    Edit the src/ckeditor.js file to add your plugin to the list of plugins which will be included in the build and to add your feature’s button to the toolbar:

    1. // The editor creator to use.
    2. import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
    3. import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
    4. import UploadAdapter from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter';
    5. import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
    6. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
    7. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
    8. import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
    9. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
    10. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
    11. import Image from '@ckeditor/ckeditor5-image/src/image';
    12. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
    13. import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
    14. import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
    15. import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
    16. import Link from '@ckeditor/ckeditor5-link/src/link';
    17. import List from '@ckeditor/ckeditor5-list/src/list';
    18. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
    19. import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'; // <--- ADDED
    20. export default class ClassicEditor extends ClassicEditorBase {}
    21. // Plugins to include in the build.
    22. ClassicEditor.builtinPlugins = [
    23. Essentials,
    24. UploadAdapter,
    25. Autoformat,
    26. Bold,
    27. Italic,
    28. BlockQuote,
    29. EasyImage,
    30. Heading,
    31. Image,
    32. ImageCaption,
    33. ImageStyle,
    34. ImageToolbar,
    35. ImageUpload,
    36. List,
    37. Paragraph,
    38. Alignment // <--- ADDED
    39. ];
    40. // Editor configuration.
    41. ClassicEditor.defaultConfig = {
    42. toolbar: {
    43. items: [
    44. 'heading',
    45. '|',
    46. 'bold',
    47. 'italic',
    48. 'link',
    49. 'bulletedList',
    50. 'numberedList',
    51. 'imageUpload',
    52. 'blockQuote',
    53. 'undo',
    54. 'redo'
    55. ]
    56. },
    57. image: {
    58. toolbar: [
    59. 'imageStyle:full',
    60. 'imageStyle:side',
    61. '|',
    62. 'imageTextAlternative'
    63. ]
    64. },
    65. // This value must be kept in sync with the language defined in webpack.config.js.
    66. language: 'en'
    67. };

    Finally, bundle the build:

    You can open the sample/index.html file in your browser to see whether the plugin was installed correctly.

    This was a quick version of how a build can be customized. Read more about in a separate guide.

    If you build the editor from source, then the process of installing a new plugin boils down to these three steps:

    • Installing the plugin package.
    • Adding it to your editor’s configuration.
    • Building your project. For example, if you wish to install the text alignment feature:
    1. npm install --save-dev @ckeditor/ckeditor5-alignment

    Edit the code that initializes the editor:

    1. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
    2. import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
    3. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
    4. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
    5. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
    6. import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'; // <--- ADDED
    7. ClassicEditor
    8. .create( document.querySelector( '#editor' ), {
    9. plugins: [ Essentials, Paragraph, Bold, Italic, Alignment ], // <--- MODIFIED
    10. toolbar: [ 'bold', 'italic', 'alignment' ] // <--- MODIFIED
    11. } )
    12. .then( editor => {
    13. } )
    14. .catch( error => {
    15. console.error( error.stack );
    16. } );

    After rebuilding your project, the new feature will be available in the editor.

    One of the possible mistakes is trying to add a plugin in this way to an existing (bundled) editor build. Installing an existing build and then trying to add a plugin to it may not work if that plugin needs to import any of the source editor modules.

    What is the difference between adding a plugin to an editor build and adding a plugin by passing the config.plugins option to the static create() method?

    The first method builds the plugin into the editor class. This means that you can then initialize the editor without passing config.plugins at all and the editor will automatically enable all built-in plugins:

    All this works because a typical src/ckeditor.js module that you can find in every editor build repository (see for example ) looks like this:

    1. import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
    2. import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
    3. import UploadAdapter from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter';
    4. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
    5. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
    6. import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
    7. // ...
    8. export default class ClassicEditor extends ClassicEditorBase {}
    9. ClassicEditor.builtinPlugins = [
    10. Essentials,
    11. UploadAdapter,
    12. Autoformat,
    13. Bold,
    14. Italic,
    15. BlockQuote,
    16. // ...
    17. ];
    18. ClassicEditor.defaultConfig = {
    19. toolbar: {
    20. items: [
    21. 'heading',
    22. 'bold',
    23. // ...
    24. ]
    25. },
    26. // ...
    27. };

    This code imports the source of the classic editor and extends it with a static builtinPlugins and defaultConfig properties where it defines a set of plugins and configuration to be used by this editor class.

    In this approach, all editor instances created by using this editor build will by default load all these built-in plugins and configuration.

    You can still use the config.removePlugins and options to override the default configuration.

    1. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
    2. import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
    3. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
    4. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
    5. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
    6. ClassicEditor
    7. .create( document.querySelector( '#editor' ), {
    8. plugins: [ Essentials, Paragraph, Bold, Italic ],
    9. toolbar: [ 'bold', 'italic' ]
    10. } )
    11. .then( editor => {
    12. console.log( 'Editor was initialized', editor );
    13. } )
    14. .catch( error => {
    15. console.error( error.stack );
    16. } );

    So, in short, both methods use very similar mechanisms. However, adding a plugin through the static builtinPlugins property (which happens in editor builds) lets you automatically enable it in all editor instances created using this editor class, while passing a plugin to will naturally affect only one instance.