Scripts

The editor provides several vendor and internal scripts to plugin developers. Script names, handles, and descriptions are documented in the table below.

WP Scripts

The editor includes a number of packages to enable various pieces of functionality. Plugin developers can utilize them to create blocks, editor plugins, or generic plugins.

Script NameHandleDescription
Blobwp-blobBlob utilities
Block Librarywp-block-libraryBlock library for the editor
Blockswp-blocksBlock creations
Block Serialization Default Parserwp-block-serialization-default-parserDefault block serialization parser implementations for WordPress documents
Block Serialization Spec Parserwp-block-serialization-spec-parserGrammar file (grammar.pegjs) for WordPress posts
Componentswp-componentsGeneric components to be used for creating common UI elements
Composewp-composeCollection of handy Higher Order Components (HOCs)
Core Datawp-core-dataSimplify access to and manipulation of core WordPress entities
Datawp-dataData module serves as a hub to manage application state for both plugins and WordPress itself
Datewp-dateDate module for WordPress
Deprecatedwp-deprecatedUtility to log a message to notify developers about a deprecated feature
Domwp-domDOM utilities module for WordPress
Dom Readywp-dom-readyExecute callback after the DOM is loaded
Editorwp-editorBuilding blocks for WordPress editors
Edit Postwp-edit-postEdit Post Module for WordPress
Elementwp-elementElement is, quite simply, an abstraction layer atop React
Escape Htmlwp-escape-htmlEscape HTML utils
Hookswp-hooksA lightweight and efficient EventManager for JavaScript
Html Entitieswp-html-entitiesHTML entity utilities for WordPress
I18Nwp-i18nInternationalization utilities for client-side localization
Is Shallow Equalwp-is-shallow-equalA function for performing a shallow comparison between two objects or arrays
Keycodeswp-keycodesKeycodes utilities for WordPress, used to check the key pressed in events like onKeyDown
List Reusable blockswp-list-reusable-blocksPackage used to add import/export links to the listing page of the reusable blocks
NUXwp-nuxComponents, and wp.data methods useful for onboarding a new user to the WordPress admin interface
Pluginswp-pluginsPlugins module for WordPress
Redux Routinewp-redux-routineRedux middleware for generator coroutines
Rich Textwp-rich-textHelper functions to convert HTML or a DOM tree into a rich text value and back
Shortcodewp-shortcodeShortcode module for WordPress
Token Listwp-token-listConstructable, plain JavaScript DOMTokenList implementation, supporting non-browser runtimes
URLwp-urlA collection of utilities to manipulate URLs
Viewportwp-viewportModule for responding to changes in the browser viewport size
Wordcountwp-wordcountWordPress word count utility

Vendor Scripts

The editor also uses some popular third-party packages and scripts. Plugin developers can use these scripts as well without bundling them in their code (and increasing file sizes).

Script NameHandleDescription
ReactreactReact is a JavaScript library for building user interfaces
React Domreact-domServes as the entry point to the DOM and server renderers for React, intended to be paired with React
MomentmomentParse, validate, manipulate, and display dates and times in JavaScript
LodashlodashLodash is a JavaScript library which provides utility functions for common programming tasks

Polyfill Scripts

The editor also provides polyfills for certain features that may not be available in all modern browsers. It is recommended to use the main wp-polyfill script handle which takes care of loading all the below mentioned polyfills.

Script NameHandleDescription
Babel Polyfillwp-polyfillEmulate a full ES2015+ environment. Main script to load all the below mentioned additional polyfills
Fetch Polyfillwp-polyfill-fetchPolyfill that implements a subset of the standard Fetch specification
Promise Polyfillwp-polyfill-promiseLightweight ES6 Promise polyfill for the browser and node
Formdata Polyfillwp-polyfill-formdataPolyfill conditionally replaces the native implementation
Node Contains Polyfillwp-polyfill-node-containsPolyfill for Node.contains
Element Closest Polyfillwp-polyfill-element-closestReturn the closest element matching a selector up the DOM tree

Bundling and code sharing

When using a JavaScript bundler like webpack, the scripts mentioned here can be excluded from the bundle and provided by WordPress in the form of script dependencies [(see wp_enqueue_script)][https://developer.wordpress.org/reference/functions/wp_enqueue_script/#default-scripts-included-and-registered-by-wordpress].

The @wordpress/dependency-extraction-webpack-plugin provides a webpack plugin to help extract WordPress dependencies from bundles. @wordpress/scripts buildscript includes the plugin by default.

原文

最終更新日: