Support

Account

Home Forums Gutenberg Load JS in editor with block.json Reply To: Load JS in editor with block.json

  • Trying again…

    Using this ACF forum post I found how to load scripts via file name in blocks.json. Which is great as I understand it’s the better way to do it (now that it’s possible) instead of what Bill Erickson’s tutorial shows.

    So @spinline since you are loading a JS file named custom.js you’d need to add in the same folder a file named custom.asset.php. In this file you can include the handle name, dependencies, and version number. Or you can leave them to be default generated. My js-file-name.asset.php looks like this:

    
    <?php
      return array(
        'dependencies' => array(
            'wp-blocks',
            'wp-element',
            'wp-i18n',
        ),
        'version'      => '1.0',
      );
    

    To read more about this, check out the WPDefinedAsset section in the Block Editor Handbook.