GrapesJS CLI

raw JSON →
4.1.3 verified Thu Apr 23 auth: no javascript

GrapesJS CLI is a command-line interface tool designed to streamline the development of GrapesJS plugins. It handles the complexities of setting up modern JavaScript build tools such as Webpack and Babel, providing a simplified and accelerated workflow for plugin authors. The current stable version, 4.1.3, focuses on dependency updates and build enhancements like the `dts` option. Historically, the CLI has undergone significant updates, including a transition to Webpack 5 in v3.0.0 and a move away from the `esm` package for internal bundling in v4.1.0, which can impact custom configurations. Its release cadence generally aligns with major GrapesJS ecosystem changes or critical dependency updates. Key differentiators for `grapesjs-cli` include its opinionated, zero-configuration approach for common plugin development scenarios, direct integration with the GrapesJS plugin structure, and features like fast project scaffolding and a built-in development server. It aims to reduce the boilerplate and configuration overhead for developers, allowing them to focus on the core plugin logic.

error Webpack options object has an unknown property '...' (e.g., 'resolve.modules'). These options were deprecated in webpack 4 and removed in webpack 5.
cause Using an outdated `webpack.config.js` that contains Webpack 4-specific configurations after upgrading grapesjs-cli to v3.0.0 (Webpack 5).
fix
Refer to the Webpack 5 migration guide and update your custom webpack.config.js to use current options and syntax.
error Error: Cannot find module 'your-plugin-name'
cause The `main` entry in your plugin's `package.json` still points to the old output path (e.g., `dist/my-plugin-name.min.js`) after the v3.0.0 breaking change.
fix
Update your package.json main field to dist/index.js.
error Error: No valid `src/index.js` (or `src/index.ts`) entry file found for your plugin.
cause The required entry point file for your GrapesJS plugin is missing or incorrectly named in the `src` directory.
fix
Ensure you have an index.js or index.ts file located directly under the src/ directory of your plugin project.
error Node.js version 12.x.x is not supported. Minimum supported Node.js version is 14.15.0.
cause Attempting to run `grapesjs-cli` with an older Node.js version than required by the CLI (v4.0.0 and above).
fix
Upgrade your Node.js installation to version 14.15.0 or newer.
breaking GrapesJS CLI v3.0.0 upgraded to Webpack 5. Custom `webpack.config.js` files may need updates to avoid deprecated options or configurations from Webpack 4.
fix Review your `webpack.config.js` against Webpack 5 documentation and update deprecated options, loaders, and plugins.
breaking With v3.0.0, the output filenames changed from `dist/my-plugin-name.min.js` to `dist/index.js`. This affects how your plugin is referenced.
fix Update the `main` field in your plugin's `package.json` to point to `dist/index.js`.
breaking Node.js 14.15.0 or newer is required since v4.0.0. Older versions of Node.js are no longer supported and will cause the CLI to fail.
fix Upgrade your Node.js environment to version 14.15.0 or later.
breaking Version 4.1.0 moved away from the `esm` package for bundling the CLI internally. While this primarily affects the CLI's internal workings, custom setups that relied on the previous bundling approach might be impacted.
fix No direct fix for users, but if experiencing unexpected build issues, ensure your environment and custom scripts are compatible with a self-bundled CLI.
gotcha When customizing Webpack through `webpack.config.js`, you must export a function that receives the default configuration object and returns a new one.
fix Ensure your `webpack.config.js` exports a function: `export default ({ config }) => { /* ... */ return { ...config, /* ... */ }; }`.
gotcha Passing options to `webpack-dev-server` via the `serve` command requires a specific JSON string format.
fix Use the `--devServer` flag with a JSON string, e.g., `npx grapesjs-cli serve --devServer='{"https": true}'`.
npm install grapesjs-cli
yarn add grapesjs-cli
pnpm add grapesjs-cli

Demonstrates the typical GrapesJS plugin development workflow including project initialization, serving, building, and an example of customizing the Webpack configuration using TypeScript types.

/**
 * This quickstart demonstrates the GrapesJS plugin development workflow using grapesjs-cli.
 * The commands below are intended to be run in a shell environment.
 */

// 1. Create a new directory for your plugin and initialize it
// mkdir grapesjs-my-plugin
// cd grapesjs-my-plugin
// npm init -y
// git init

// 2. Install the GrapesJS CLI as a development dependency
// npm i -D grapesjs-cli

// 3. Initialize your plugin project. Use '-y' to skip interactive questions.
// npx grapesjs-cli init -y --user=your-github-username

// 4. Start the development server. Access your plugin demo at http://localhost:8080.
// npx grapesjs-cli serve
// You can also pass custom webpack-dev-server options:
// npx grapesjs-cli serve --devServer='{"https": true}'

// 5. Build your plugin for production. This generates output in the 'dist' directory.
// npx grapesjs-cli build

// Example: Custom webpack.config.js for advanced configurations (placed in your plugin's root directory)
// This JavaScript code block is runnable as a conceptual example of the config file structure.
/** @type {import('webpack').Configuration} */
const customWebpackConfig = ({ config }) => {
    // `config` is the default webpack configuration provided by grapesjs-cli
    const isBuild = config.mode === 'production'; // Differentiate build from serve command

    return {
        ...config,
        // Example: Add a new rule for handling SVG files
        module: {
            rules: [
                {
                    test: /\.svg$/,
                    use: ['@svgr/webpack'],
                },
                ...config.module.rules,
            ],
        },
        // Example: Customize an existing plugin or add a new one
        plugins: [
            ...(config.plugins || []),
            // new MyCustomWebpackPlugin(),
        ],
    };
};

// In a real scenario, this would be exported from a webpack.config.js file:
// export default customWebpackConfig;

console.log('GrapesJS CLI workflow and custom webpack config demonstrated.');