2

I regularly use @wordpress/scripts for building both blocks and non-block components. Recently, I started working in a new plugin that registers both some blocks and non-block components that add additional panels using the registerPlugin() function. This is the structure of my /src directory:

/src
    /blocks
        /my-first-block
            block.json
            ...
        /my-second-block
            block.json
            ...
        /my-third-block 
            block.json
            ...
    /components
        /my-first-panel
            index.js
        /my-second-panel
            index.js
    index.js
    style.css

This is the content of the root index.js file:

import { registerPlugin } from '@wordpress/plugins';

import FirstPanelOptionsPanelComponent from './components/my-first-panel';
import SecondPanelOptionsPanelComponent from './components/my-second-panel';
import './style.scss';

registerPlugin('first-panel-options-panel', {
    render: FirstPanelOptionsPanelComponent,
});

registerPlugin('second-panel-options-panel', {
    render: SecondPanelOptionsPanelComponent,
});

When you run the wp-scripts build script from the @wordpress/scripts package, it only builds the blocks located in the /src directory. However, if you specifically run wp-scripts build src/index.js, it builds the components but exclude the blocks.

Is there a way to build BOTH the blocks and the non-block components at once?

1 Answer 1

4

I'm pasting the answer I got from a developer in the Gutenberg repository.

Just add a webpack.config.js file at the root of your project with the following contents:

const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

module.exports = {
    ...defaultConfig,
    entry: {
        ...defaultConfig.entry(),
        index: './src/index.js',
    },
};

This will build all the blocks in /src/blocks/ folder and also compile the /src/index.js file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.