ahmadawais / create-guten-block

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

📦 NEW: @wordpress/api-fetch as an available external #249

Closed moreira-dev closed 5 years ago

moreira-dev commented 5 years ago

Allows using the external wp.apiFetch method. Otherwise, if you try to import it from the @wordpress/api-fetch package, it won't have the REST API base URL initialized.

Example of usage:

import apiFetch from '@wordpress/api-fetch';

apiFetch( { path: '/wp/v2/posts' } ).then( posts => { console.log( posts ); } );

ahmadawais commented 5 years ago

Thank you! 👌

ahmadawais commented 5 years ago

Successfully published:

ankitsingh101 commented 4 years ago

So i have to add in init.php wp_register_script( 'idb_image_slider-cgb-block-js', // Handle. plugins_url( '/dist/blocks.build.js', dirname( FILE ) ), // Block.build.js: We register the block here. Built with Webpack. array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' , 'wp-api-fetch'), // Dependencies, defined above. null, // filemtime( plugin_dir_path( DIR ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time. true // Enqueue the script in the footer. );

and in blocks.build.js

import apiFetch from '@wordpress/api-fetch';