1.2.0
Whats New?
WordPress Dependency Extraction
Support for usage of @wordpress
packages within code to allow for more native and standard usage of Gutenberg elements.
// Previously
const { registerBlockType } = wp.block;
const { __ } = wp.i18n;
// Now supported:
import { registerBlockType } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
Accessing Dependency Array
As outlined in the Working with your Assets page on the wiki, asset information is placed in global PHP constants from the inc/asset-settings.php file. If we have an entry point of editor.js
in a plugin/project called test-plugin
that takes advantage of @wordpress
packages, a new constant will be defined.
Constants with the suffix of _DEPENDENCIES
will contant the array required.
define( 'TEST_PLUGIN_EDITOR_CSS', 'editor.css' );
define( 'TEST_PLUGIN_EDITOR_JS', 'editor.js' );
define( 'TEST_PLUGIN_EDITOR_DEPENDENCIES', ["react","wp-blocks","wp-i18n"] );
define( 'TEST_PLUGIN_VERSION', 'v0.0.0' );
Any entrypoints and subsequent scripts without dependencies will contain an empty array.
Aliases
To aide with directory traversion within components or files we can add a number of predefined aliases that allow for easier time with referencing directories based around a common structure that we use for our projects. This means we can avoid backstepping through directories to get back to a base directory. For example we may find we have a situation where we're backstepping to get to the components
directory like this;
const { MyButtons } from '../../../components/buttons';
With aliases, this can easily be replaced with the following if required;
const { MyButtons } from '@Components/buttons';
The following are currently supported;
@Components
→{project-root}/src/components
Components
→{project-root}/src/components
@Static
→{project-root}/src/static
Static
→{project-root}/src/static
@Utils
→{project-root}/src/utils
Utils
→{project-root}/src/utils
Static File Checking
To ensure that file with extensions such as js
and php
are being flagged as in the incorrect location, a file check has been added with a warning. This has been implemented using a custom plugin to handled checks against files as webpack parses through them. Warnings will be shown in a similar manner to other parsing or linting warnings in the post compile report within the CLI.
Linting Changes
- Disables the
react/require-default-props
rule as this is now depreciated.
Change Log
- Adds alias resolving support to projects.
- Adds support for
@wordpress
packages using DependencyExtraction as a custom extension of@wordpress/dependency-extraction-webpack-plugin
package. See #60. - Removes
HTMLWebpack
plugin. - Adds custom
TemplateGenerator
plugin. - Refactors
assetSettings
template function. - Adds custom
AssetMessage
plugin. - Adds rules for
AssetMessage
.