Topics

On this page

Last updated on Nov 6, 2024

Directory Structure Best Practices

Organizing your Gutenberg block codebase is essential for maintainability and scalability. A well-structured folder layout makes it easier to locate files, manage dependencies, and collaborate with other developers.

Blocks

Separate blocks into individual folders, each containing the block’s JavaScript, and CSS files. This isolation ensures that each block is self-contained and can be easily reused or extended.

Example:

  /assets/src/blocks/

    ├── block-name/

    │   ├── block.json

    │   ├── edit.js

    │   ├── index.js

    │   ├── save.js

    │   ├── editor.scss

    │   ├── style.scss

    |   ├── variations.js

    |   ├── view.js

    |   ├── styles/

    |   |   ├── style.scss

    |   |   ├── variations/

    |   |       ├── variation-name.scss

    |   ├── components/

Block Styles

here’s a structure for core/blocks & custom/blocks.

Core Blocks

Custom Blocks

Block Variations

here’s the structure for core/block-variations & custom/block-variations.

Core Blocks

Custom Blocks

Block Extensions

To extend blocks:


Contributor

Utsav Patel

Utsav

Utsav Patel

Software Engineer