WEBINARNo AI, your AI, or a team of agents: Introducing CKEditor Editing Toolkit. REGISTER NOW!
Sign up (with export icon)

Ready-to-use webpack examples

Show the table of contents
Tip

Let an AI coding agent set up the editor bundle for you. The official ckeditor-bundle skill adds scripts that build the editor bundle from the editor of your application. The scripts also check the bundle with test data and upload it. Install the CKEditor 5 skills:

npx skills add ckeditor/skills

Then ask your agent, for example: “Set up the editor bundle for CKEditor Cloud Services”. Review the changes before you commit them. See the Using CKEditor 5 with AI coding agents guide for setup options and supported agents.

This article presents examples of a CKEditor 5 editor bundle in Node.js. An editor bundle is required by CKEditor Cloud Services to enable the document storage, import and export as well as connection optimization features.

Note

This article presents ready-to-use examples. If you need a step-by-step guide or have an existing CKEditor 5 setup that needs to be adjusted to create a bundle, refer to the Editor bundling with webpack guide. If you use Vite, refer to the Editor bundling with Vite guide.

Example bundle

The following example presents a minimalistic editor bundle setup. It is based on 3 files - package.json, ckeditorcs.js and webpack.config.js, and is ready to use.

Dependencies

This example uses the following dependencies:

  • ckeditor5
  • ckeditor5-premium-features
  • webpack
  • webpack-cli
  • mini-css-extract-plugin
  • css-loader

With the above, the package.json file should look like the one below.

{
	"name": "ckeditorcs-bundle",
	"version": "1.0.0",
	"private": true,
	"dependencies": {
		"ckeditor5": "^49.0.0",
		"ckeditor5-premium-features": "^49.0.0"
	},
	"devDependencies": {
		"css-loader": "^7.1.5",
		"mini-css-extract-plugin": "^2.10.2",
		"webpack": "^5.111.1",
		"webpack-cli": "^7.2.3"
	}
}

Editor build configuration

The ckeditorcs.js file presents an example of an editor build configuration. It is used by the bundler as an entry file.

// ckeditorcs.js

import {
	// The editor base creator to use.
	ClassicEditor,
	// All plugins that you would like to use in your editor.
	Essentials,
	Paragraph,
	Bold,
	Italic
} from 'ckeditor5';

import {
	// All premium plugins that you would like to use in your editor.
	RealTimeCollaborativeEditing
} from 'ckeditor5-premium-features';

class CKEditorCS extends ClassicEditor {}

// Load all plugins you would like to use in your editor this way.
// This is the only way to load plugins into the editor which will then be used in CKEditor Cloud Services.
CKEditorCS.builtinPlugins = [
	Essentials,
	Paragraph,
	Bold,
	Italic,
	RealTimeCollaborativeEditing
];

// Export your editor.
export default CKEditorCS;

Bundler configuration

The webpack.config.js file presents the bundler configuration. Here webpack is used as the bundler.

// webpack.config.js

const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );

module.exports = {
	entry: './ckeditorcs.js', // Your editor build configuration.
	output: {
		filename: 'editor.bundle.js', // Content of this file is required to upload to CKEditor Cloud Services.
		library: 'CKEditorCS', // It is required to expose your editor class under the "CKEditorCS" name!

		libraryTarget: 'umd',
		libraryExport: 'default',
		clean: true
	},
	plugins: [
		new MiniCssExtractPlugin()
	],
	module: {
		parser: {
			javascript: {
				dynamicImportMode: 'eager'
			}
		},
		rules: [
			{
				test: /\.css$/i,
				use: [MiniCssExtractPlugin.loader, 'css-loader']
			}
		]
	},
	performance: {
		// Warn when the bundle gets close to the 10 MB upload limit.
		hints: 'warning',
		maxAssetSize: 9 * 1024 * 1024, // 9 MiB
		maxEntrypointSize: 9 * 1024 * 1024
	}
};

Generating the bundle

Run the following commands inside the folder with these files:

npm install
npx webpack --mode production

This command will result in the generation of the ./dist/editor.bundle.js file. This is the bundle file which then should be uploaded to CKEditor Cloud Services server.

The upload request, with the bundle, the configuration, and the test data, must be smaller than 10 MB. Keep the .js extension in output.filename, because webpack minifies only files that end with .js.

Example bundle (legacy configuration)

The following example presents a minimalistic editor bundle setup. It is based on 3 files - package.json, ckeditorcs.js and webpack.config.js, and is ready to use.

Dependencies

This example uses the following dependencies:

  • @ckeditor/ckeditor5-editor-classic
  • @ckeditor/ckeditor5-basic-styles
  • @ckeditor/ckeditor5-essentials
  • @ckeditor/ckeditor5-paragraph
  • @ckeditor/ckeditor5-real-time-collaboration
  • @ckeditor/ckeditor5-dev-utils
  • @ckeditor/ckeditor5-theme-lark
  • css-loader
  • postcss-loader
  • raw-loader
  • style-loader
  • webpack
  • webpack-cli

With the above, the package.json file should look like the one below:

{
	"name": "ckeditorcs-bundle",
	"version": "1.0.0",
	"private": true,
	"dependencies": {
		"@ckeditor/ckeditor5-editor-classic": "41.4.2",
		"@ckeditor/ckeditor5-basic-styles": "41.4.2",
		"@ckeditor/ckeditor5-essentials": "41.4.2",
		"@ckeditor/ckeditor5-paragraph": "41.4.2",
		"@ckeditor/ckeditor5-real-time-collaboration": "41.4.2"
	},
	"devDependencies": {
		"@ckeditor/ckeditor5-dev-utils": "^40.2.2",
		"@ckeditor/ckeditor5-theme-lark": "41.4.2",
		"css-loader": "^5.2.7",
		"postcss-loader": "^4.3.0",
		"raw-loader": "^4.0.2",
		"style-loader": "^2.0.0",
		"webpack": "^5.91.0",
		"webpack-cli": "^4.10.0"
	}
}

Editor build configuration

The ckeditorcs.js file presents an example of an editor build configuration. It is used by the bundler as an entry file.

// The editor base creator to use.
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

// All plugins that you would like to use in your editor.
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
import RealTimeCollaborativeEditing from '@ckeditor/ckeditor5-real-time-collaboration/src/realtimecollaborativeediting';

class CKEditorCS extends ClassicEditor {}

// Load all plugins you would like to use in your editor this way.
// This is the only way to load plugins into the editor which will then be used in CKEditor Cloud Services.
CKEditorCS.builtinPlugins = [
	Essentials,
	Paragraph,
	Bold,
	Italic,
	RealTimeCollaborativeEditing
];

// Export your editor.
export default CKEditorCS;

Bundler configuration

The webpack.config.js file presents an example of the bundler configuration. Here webpack is used as the bundler.

const { styles } = require( '@ckeditor/ckeditor5-dev-utils' );

module.exports = {
	entry: './ckeditorcs.js', // Your editor build configuration.
	output: {
		filename: 'editor.bundle.js', // Content of this file is required to upload to CKEditor Cloud Services.
		library: 'CKEditorCS', // It is required to expose your editor class under the "CKEditorCS" name!

		libraryTarget: 'umd',
		libraryExport: 'default'
	},
	module: {
		parser: {
			javascript: {
				dynamicImportMode: 'eager'
			}
		},
		rules: [
			{
				test: /\.svg$/,
				use: [ 'raw-loader' ]
			},
			{
				test: /\.css$/,
				use: [
					{
						loader: 'style-loader',
						options: {
							injectType: 'singletonStyleTag'
						}
					},
					{
						loader: 'css-loader'
					},
					{
						loader: 'postcss-loader',
						options: {
							postcssOptions: styles.getPostCssConfig( {
								themeImporter: {
									themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
								},
								minify: true
							} )
						}
					}
				]
			}
		]
	},
	performance: {
		// Warn when the bundle gets close to the 10 MB upload limit.
		hints: 'warning',
		maxAssetSize: 9 * 1024 * 1024, // 9 MiB
		maxEntrypointSize: 9 * 1024 * 1024
	}
};

Generating the bundle

Run the following commands inside the CKEditor 5 package folder:

npm install
npx webpack --mode production

This command will result in the generation of the ./dist/editor.bundle.js file. This is the bundle file which then should be uploaded to CKEditor Cloud Services server.

The upload request, with the bundle, the configuration, and the test data, must be smaller than 10 MB. Keep the .js extension in output.filename, because webpack minifies only files that end with .js.