I grabbed gallery block from Gutenberg github (Gallery block) and I wanted to modify it in following way: only first image is output to the html, while the rest are sent to lightbox javascript plugin.

However, when compiled and used, I am getting a bunch of excess dependencies in the frontend like lodash, react, react.dom and so on. Gutenberg does not output these dependencies in the frontend.

How to prevent outputting these dependencies? they are getting outputed in index.asset.php. I am using @wordpress/create-block to work and compile with blocks.

  • Have you considered instead using the official build tools via WP Scripts? Could the change you wanted not be achieved via filters in javascript or block styles? That would avoid building a new block entirely, and make the content more portable, and your frontend JS and CSS would only need to target some HTML attributes
    – Tom J Nowell
    Nov 2 '20 at 9:54
  • Sorry, my mistake, I used @wordpress/create-block, it is official package, as I understand, it uses WP Scripts. I am not using filters, because this block should co-exist with regular gallery block
    – Lovor
    Nov 2 '20 at 10:17
  • I mean to say you can add a new block variation of the gallery, allowing users to select this new styles or variation. This does not replace the gallery. Jetpack manages this by adding variations for masonry galleries or tiled galleries, without introducing new blocks
    – Tom J Nowell
    Nov 2 '20 at 11:21

It looks it was some kind of internal malfunctioning of webpack. After deleting everything from plugin directory (saving src files aside) and again installing @wordpress/create-block, the problem was solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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