ahmadawais / create-guten-block

📦 A zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.
https://Awais.dev/cgb-post
MIT License
3.15k stars 328 forks source link

What's the work flow for including js libraries in a block? #264

Open yangkennyk opened 4 years ago

yangkennyk commented 4 years ago

I'm new to creating gutenberg blocks and react (so still learning!)

If I needed a js library for example like https://kenwheeler.github.io/slick/ in my block.

Should the initialization etc be included in the block or should it be a separate file?

If it's a separate file, how would I be able to optimize so that the library is only loaded if the block is used on a page?

michaelslevy commented 4 years ago

You'd enqueue the JS and CSS in the init.plugin file. Then add the markup in the block JS file. You'd need to make a nested block to add the slides.