How to Build a GrapesJS Plugin From Scratch Using GrapesJS CLI

Step-by-step tutorial on creating a GrapesJS plugin with CLI. Scaffold, develop, test, and publish plugins easily with this complete guide

DevFuture Development
DevFuture Development
October 6, 2025a month ago
By DevFuture
8 min read708 views

Introduction

GrapesJS is one of the most flexible open-source frameworks for creating drag-and-drop web builders. Its true power lies in its plugin ecosystem, which allows developers to extend the editor with new blocks, traits, panels, commands, and integrations.

This article provides a complete, step-by-step guide on how to build a GrapesJS plugin from scratch using the official GrapesJS CLI. It is designed for developers, agencies, and companies looking to create custom solutions or contribute to the growing GrapesJS community.


Key takeaways from this guide:

  • What GrapesJS and GrapesJS CLI are
  • How to scaffold a new plugin project with CLI
  • Writing the first plugin logic (blocks, traits, commands)
  • Running a dev server and building production-ready code
  • Monetization opportunities

What is GrapesJS?

GrapesJS is an open-source, MIT-licensed web builder framework developed in 2016. It is widely used for:

  • Website builders
  • Email template editors
  • Page and document design tools
  • Drag-and-drop interfaces in SaaS products

Core features:

  • Drag-and-drop block manager
  • Custom traits and style system
  • Device preview modes (desktop, tablet, mobile)
  • Layer manager and style panel
  • Fully extensible plugin system

👉 Plugins are essential because they allow developers to build specialized features without bloating the GrapesJS core.


What is GrapesJS CLI?

The GrapesJS CLI is the official command-line interface for plugin development. It eliminates the complexity of setting up build systems by providing:

  • Scaffolding → Generate a ready-to-use plugin project with one command
  • Development server → Run and test the plugin live inside GrapesJS
  • Production build → Output minified, optimized code for distribution

In short, GrapesJS CLI provides everything required to start developing plugins immediately.

Step 1: Initialize a Plugin with GrapesJS CLI

To create a plugin named grapesjs-my-plugin:


Create a new folder:

mkdir grapesjs-my-plugin
cd grapesjs-my-plugin

Initialize npm:

npm init -y

Install the CLI:

npm install --save-dev grapesjs-cli

Scaffold the plugin project:

npx grapesjs-cli init

This generates a full project structure with an entry file at src/index.js.


Run the development server:

npx grapesjs-cli serve

The plugin will load inside GrapesJS at http://localhost:8080.

Build for production:

npx grapesjs-cli build

The compiled plugin will be available in the dist/ folder.


Step 2: Project Structure

A scaffolded GrapesJS CLI project includes:

grapesjs-my-plugin/

├── src/
│  └── index.js    ← main plugin entry file
├── dist/        ← compiled distribution files
├── package.json
├── README.md
├── babel.config.js
├── webpack.config.js  ← optional custom config
  • src/index.js → contains the plugin logic
  • dist/ → production-ready build output
  • README.md → documentation template
  • webpack.config.js → allows customization of the default build configuration

Step 3: Writing Plugin Logic

In src/index.js, add plugin features.

Example: Adding a block

export default (editor, opts = {}) => {
 const bm = editor.BlockManager;

 bm.add('hello-block', {
  label: 'Hello Block',
  category: 'Basic',
  content: '<div class="hello-block">Hello from the plugin!</div>',
 });
};

Example: Adding a custom trait

editor.TraitManager.addType('uppercase', {
 createInput() {
  const el = document.createElement('input');
  el.type = 'checkbox';
  return el;
 },
 onUpdate({ elInput, component }) {
  const checked = elInput.checked;
  component.addStyle({ 'text-transform': checked ? 'uppercase' : 'none' });
 }
});

Example: Adding a command and panel button

editor.Commands.add('say-hello', {
 run(editor) {
  alert('Hello from GrapesJS plugin!');
 }
});

editor.Panels.addButton('options', {
 id: 'say-hello-btn',
 className: 'fa fa-bell',
 command: 'say-hello',
 attributes: { title: 'Say Hello' },
 persist: true,
});

Step 4: Running and Debugging

When using npx grapesjs-cli serve:

  • Monitor events with editor.on('event-name', callback)
  • Inspect selected components with editor.getSelected()
  • Test traits and style updates directly in the live editor

Step 5: Building and Publishing

Create a production build:

npx grapesjs-cli build

Complete the README.md with:

  • Plugin description
  • Configuration options (opts)
  • Example usage snippets
  • Demo link

Publish to npm:

npm publish

Share on:

  • GJS.Market
  • GitHub repository
  • Open-source developer communities

Step 6: SEO & Distribution Strategy

Recommended actions:

  • Publish technical blog posts with usage examples
  • Write tutorials on Dev.to, Medium, Hashnode
  • Record video walkthroughs on YouTube
  • Submit to Reddit r/webdev and Hacker News
  • Create backlinks from related open-source projects

Step 7: Monetization Opportunities

Companies and developers can:

  • Release a Pro version with advanced features
  • Provide custom integrations for SaaS and agencies
  • Sell plugins on GJS.Market
  • Offer paid support, maintenance, or consulting

Key Takeaways

  • GrapesJS is a powerful framework, but plugins make it truly flexible.
  • GrapesJS CLI provides an easy way to scaffold, serve, and build plugins.
  • Start with simple blocks or traits, then expand functionality.
  • Documentation and SEO are critical for plugin adoption.
  • Monetization options exist for commercial use cases.

Conclusion

With the GrapesJS CLI, building plugins becomes a streamlined process: scaffold the project, add logic, run a live server, and build production-ready files.

Plugins not only extend GrapesJS but also open opportunities for businesses to innovate, grow visibility, and generate revenue.


👉 Run:

npx grapesjs-cli init

to start building your own GrapesJS plugin today.

Share this postTwitterFacebookLinkedIn
Published via
DevFuture Development
DevFuture Development
Visit shop →

More from DevFuture Development

Discover other insightful posts and stay updated with the latest content.

View all posts

Premium plugins from DevFuture Development

Hand-picked paid additions crafted by this creator.

Visit shop →