Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add details on installing/using packages #12595

Merged
merged 2 commits into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion docs/designers-developers/developers/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,39 @@

Gutenberg exposes a list of JavaScript packages and tools for WordPress development.

## Using the packages
## Using the packages via WordPress global

JavaScript packages are available as a registered script in WordPress and can be accessed using the `wp` global variable.

If you wanted to use the `PlainText` component from the editor module, first you would specify `wp-editor` as a dependency when you enqueue your script:

```php
wp_enqueue_script(
'my-custom-block',
plugins_url( $block_path, __FILE__ ),
array( 'wp-blocks', 'wp-editor', 'wp-element', 'wp-i18n' )
);
```

After the dependency is declared, you can access the module in your JavaScript code using the global `wp` like so:
```js
const { PlainText } = wp.editor;

```

## Using the packages via npm

All the packages are also available on [npm](https://www.npmjs.com/org/wordpress) if you want to bundle them in your code.

Using the same `PlainText` example, you would install the editor module with npm:

```bash
npm install @wordpress/editor --save
```

Once installed, you can access the component in your code using:

```js
import { PlainText } from '@wordpress/editor';
```