Issue #2377💬 AnsweredOpened November 5, 2019by arunkumar4131 reactions

Using the grapes cli to create a plugin

快速解答by pouyamiralayi1

@arunkumar413 this issue must be posted at grapesjs-cliWhich of the following should be used to define components? you must define your components at `components.js file. loadComponents is the named import of that file. after that you must define your blocks inside blocks.js` file in order to expose your defined compo...

Read full answer below ↓

Question

Hi Team,

I'm trying to use the grapes cli tool (https://github.com/artf/grapesjs-cli) to create a plugin to be used with a react project. The cli tool created blocks.js, components.js and an index.js files. The index.js file contains the below code:

export default (editor, opts = {}) => {
  const options = {
    ...{
      // default options
    },
    ...opts
  };

  // Add components
  loadComponents(editor, options);
  // Add blocks
  loadBlocks(editor, options);

  // TODO Remove
  editor.on("load", () =>
    editor.addComponents(
      `<div style="margin:100px; padding:25px;">
     
          
        </div>`,
      { at: 0 }
    )
  );

Which of the following should be used to define components? Is the loadComponents used for loading the components defined in the components.js or adding the components?

  1. loadComponents(editor, options)
  2. editor.addComponents( )
  3. Or use the components.js file

Could you please make a few codesandboxes to helps us better understand on how to use grapesjs with react, jsx, UI tool kits such as material-UI etc,.

Thanks, Arun

Answers (2)

pouyamiralayiNovember 5, 2019

@arunkumar413 this issue must be posted at grapesjs-cli

Which of the following should be used to define components?

you must define your components at components.js file. loadComponents is the named import of that file. after that you must define your blocks inside blocks.js file in order to expose your defined components for usage. cheers!

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.