javascript – Where to include JS library in gutenberg blocks


Lets say that I want to make a block with animations from an external library as GSAP.

I have this file structure (files not needed omitted):

 │   └─ blocks
 │       └─ my-block-1
 │          ├─ block.json
 │          ├─ index.js
 │          ├─ edit.js
 │          └─ save.js
 └───── package.json

 │   └─ app.js (imported GSAP as a module)
 └───── package.json (it includes GSAP)

I have imported GSAP as a module in my theme inside my-theme/app.js for theme animations.

The main question is, for use GSAP in a block:

Should I use the GSAP in the theme? If yes, the plugin will be theme dependent.

Should I include GSAP in the my-block-1/save.js?

If yes: It doesn’t matter that the library is redundant with the theme’s library?

Also, will the library be loaded every time a block is included in the editor? (Many blocks = many redundant libraries)

aitor 1 month 2022-10-22T03:04:45-05:00 0 Answers 0 views 0

Leave an answer