最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

front end - Excess dependencies

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Nov 2, 2020 at 10:20 Lovor asked Nov 2, 2020 at 9:18 LovorLovor 9969 silver badges16 bronze badges 3
  • 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 Commented Nov 2, 2020 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 Commented Nov 2, 2020 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 Commented Nov 2, 2020 at 11:21
Add a comment  | 

1 Answer 1

Reset to default 1

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论