WordPress / gutenberg-examples

Examples for extending WordPress/Gutenberg with blocks.
1.2k stars 316 forks source link

block.json must be inside "src" folder when using custom or multiple entry points #217

Closed alexdelgado closed 2 years ago

alexdelgado commented 2 years ago

I've just submitted an issue to the Gutenberg repo regarding the placement of block.json because it's not very clear that when you use a custom entry-point or multiple entry points such as "editorScript" or "viewScript" webpack expects block.json to live inside the src folder. In all your examples where there is a src folder, block.json is not inside that folder which is confusing unless you realize that works because in all the examples you are using the default entry point of src/index.js.

Additionally, if you did move block.json into the src folder per the webpack config, it would look for src/build/index.js instead of src/index.js, because the file:... path is relative to the src directory, not the package directory.

I'm raising this issue here as well as Gutenberg because I believe block.json shouldn't live inside src but also because:

  1. You should document that "gotcha"
  2. The file:... values are technically incorrect but it's not being caught because wepack uses the default entry point of src/index.js
alexdelgado commented 2 years ago

It is worth noting the work-around for anyone who doesn't want to put block.json in the src folder can create a webpack.config.js file in the root of the block directory and set the entries manually.

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

module.exports = {
    ...defaultConfig,
    entry: {
        index: './src/index.js',
        view: './src/view.js'
    }
}
ryanwelcher commented 2 years ago

Hello and thanks for taking the time to open this issue!

This is probably better discussed in https://github.com/WordPress/gutenberg/issues/40771 as this repo is meant to store examples and simply uses the APIs provided. I'll add my comments there 😄

ryanwelcher commented 2 years ago

@alexdelgado based on the conversation in https://github.com/WordPress/gutenberg/issues/40771, I'm going to close this out. Please feel free to reopen if I have missed something. Thanks again for opening it!