Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd dependency management section #17489
Conversation
Adds new section on how to use index.deps.json for automatic dependency management Includes various minor rewording updates
Whats the plan here because it looks from the outside that the |
@fabiankaegy good question, I haven't seen |
@fabiankaegy I found it #17298 looks like it is just 3 days old, which is why I hadn't seen it before. Guess it took too long to get around to documenting .deps.json and it got replaced. |
@mkaz Yeah I felt the same way but a basic include saved in a variable and then accessing the |
@fabiankaegy I updated the docs with the |
@@ -148,20 +148,19 @@ Likewise, you do not need to include `node_modules` or any of the above configur | |||
|
|||
### Dependency Management | |||
|
|||
The build step also produces a `index.deps.json` file that contains a JSON array of the wp packages required for your block. For our simple example above would be `["wp-blocks","wp-polyfill"]` | |||
Using wp-scripts ver 5.0.0+ build step will also produce a `index.asset.php` file that contains an array of dependencies and version number for your block. For our simple example above is something like: |
This comment has been minimized.
This comment has been minimized.
fabiankaegy
Sep 19, 2019
Member
It generates this .asset.php
file for each of the entry points. so if you add your cutsom entry points they will get this file swell :)
This comment has been minimized.
This comment has been minimized.
mkaz
Sep 19, 2019
Author
Member
That is true, but our JS tutorial is intended for beginners and does not include any description on how one would configure multiple entry points. It is more of an advanced topic better left for package documentation not this tutorial.
wp_register_script( | ||
'myguten-block', | ||
plugins_url( 'build/index.js', __FILE__ ), | ||
$dependencies | ||
$depver['dependencies'], |
This comment has been minimized.
This comment has been minimized.
fabiankaegy
Sep 19, 2019
Member
One think that I found useful was that its just an array and that you can use functions like array_merge()
to add your own custom dependencies to it if you need that.
This comment has been minimized.
This comment has been minimized.
gziolo
Sep 19, 2019
Member
Yes, we do it in Gutenberg and this is going to be added to WP core now we can include static PHP file. This was also the reason why we changed the format. We plan to add more details to the file to eventually make it possible to pass only the name of the file when registering an asset. The rest would be handy behind the scenes
Nice addition, I left some minor comments and further explanation about the asset file. |
docs/designers-developers/developers/tutorials/javascript/js-build-setup.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/js-build-setup.md
Outdated
Show resolved
Hide resolved
I know it's too late now, but I just saw this. |
@@ -1,18 +1,18 @@ | |||
# JavaScript Build Setup | |||
|
|||
This page covers how to set up your development environment to use the ESNext and [JSX](https://reactjs.org/docs/introducing-jsx.html) syntaxes. ESNext is JavaScript code written using features that are only available in a specification greater than ECMAScript 5 (ES5 for short). JSX is a custom syntax extension to JavaScript which helps you to describe what the UI should look like. | |||
This page covers how to set up your development environment to use the ESNext and [JSX](https://reactjs.org/docs/introducing-jsx.html) syntaxes. ESNext is JavaScript code written using features that are only available in a specification greater than ECMAScript 5 (ES5 for short). JSX is a custom syntax extension to JavaScript that allows you write JavaScript in a more familiar tag syntax. |
This comment has been minimized.
This comment has been minimized.
jrchamp
Sep 20, 2019
Contributor
This page covers how to set up your development environment to use the ESNext and [JSX](https://reactjs.org/docs/introducing-jsx.html) syntaxes. ESNext is JavaScript code written using features that are only available in a specification greater than ECMAScript 5 (ES5 for short). JSX is a custom syntax extension to JavaScript that allows you write JavaScript in a more familiar tag syntax. | |
This page covers how to set up your development environment to use the ESNext and [JSX](https://reactjs.org/docs/introducing-jsx.html) syntaxes. ESNext is JavaScript code written using features that are only available in a specification greater than ECMAScript 5 (ES5 for short). JSX is a custom syntax extension to JavaScript that allows you to write JavaScript in a more familiar tag syntax. |
|
||
Most browsers can not interpret or run ESNext and JSX syntaxes, so we use a transformation step to convert these syntaxes to code that browsers can understand. | ||
|
||
There are a few reasons to use ESNext and the extra step. First, it makes for simpler code that is easier to read and write. Using a transformation step allows for tools to optimize the code to work on the widest variety of browsers. Also, by using a build step you can organize your code into smaller modules and files that can be bundled together into a single download. | ||
|
||
There are different tools that can perform this transformation or build step, but WordPress uses webpack and Babel. | ||
There are different tools that can perform this transformation or build step, WordPress uses webpack and Babel. |
This comment has been minimized.
This comment has been minimized.
jrchamp
Sep 20, 2019
Contributor
There are different tools that can perform this transformation or build step, WordPress uses webpack and Babel. | |
There are different tools that can perform this transformation or build step; WordPress uses webpack and Babel. |
@@ -22,15 +22,15 @@ For a quick start, you can use one of the examples from the [Gutenberg Examples | |||
|
|||
Both webpack and Babel are tools written in JavaScript and run using [Node.js](https://nodejs.org/) (node). Node.js is a runtime environment for JavaScript outside of a browser. Simply put, node allows you to run JavaScript code on the command-line. | |||
|
|||
First, you need to set up node for your development environment. The steps required change depending on your operating system, but if you have a package manager installed, setup can be as straightforward as: | |||
First, you need to set up node for your development environment. The steps required depend on your operating system, if you have a package manager installed, setup can be as straightforward as: |
This comment has been minimized.
This comment has been minimized.
jrchamp
Sep 20, 2019
Contributor
First, you need to set up node for your development environment. The steps required depend on your operating system, if you have a package manager installed, setup can be as straightforward as: | |
First, you need to set up Node.js for your development environment. The steps required depend on your operating system. If you have a package manager installed, setup can be as straightforward as: |
@@ -119,7 +119,7 @@ To configure npm to run a script, you use the scripts section in `package.json` | |||
|
|||
You can then run the build using: `npm run build`. | |||
|
|||
After the build finishes, you will see the built file created at `build/index.js`. | |||
After the build finishes, you will see the built file created at `build/index.js`. Enqueue this file in the admin screen as shown in Step 2, and the block will load in the editor. |
This comment has been minimized.
This comment has been minimized.
jrchamp
Sep 20, 2019
Contributor
There is nothing labeled "Step 2". It would be best to reference something that exists/can be found on the current page.
Using wp-scripts ver 5.0.0+ build step will also produce a `index.asset.php` file that contains an array of dependencies and version number for your block. For our simple example above is something like: | ||
`array('dependencies' => array('wp-element', 'wp-polyfill'), 'version' => 'fc93c4a9675c108725227db345898bcc');` | ||
|
||
Here is how to use this asset file to automatically set the dependency list for enqueing the script. This prevents having to manually update the dependencies, it will be created based on the package imports used within your block. |
This comment has been minimized.
This comment has been minimized.
jrchamp
Sep 20, 2019
Contributor
enqueuing or enqueueing; not enqueing. My browser only likes the first one.
* Add dependency management section Adds new section on how to use index.deps.json for automatic dependency management Includes various minor rewording updates * Update documentation to use wp-scripts 5.0.0 format * Switch variable name, bump scripts to 5.0.0
Updates per @jrchamp review in WordPress#17489
mkaz commentedSep 19, 2019
•
edited
Description
Adds new section Dependency Management to the JavaScript Tutorial that explains how to use
index.asset.php
from wp-scripts 5.0.0Bonus: while reading through the document I updated various rewording and simplified a few bits.
Gutenberg Examples repo updated in:
WordPress/gutenberg-examples#89
Fixes #17423
How has this been tested?
Follow example instructions and confirm dependency loading works as described.
Types of changes
Documentation update, view live on branch here