Skip to content
PHP utilities for WordPress to aid including dynamic Webpack-generated assets in themes or plugins.
PHP
Branch: master
Clone or download
kadamwhite Merge pull request #12 from humanmade/warn-on-https-dev-issues
Implement basic dev server HTTPS certificate error detection
Latest commit 4f961f5 Aug 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
inc Implement basic dev server HTTPS certificate error detection Aug 2, 2019
.gitignore
.travis.yml
LICENSE Add GPLv2 license and barebones README Apr 8, 2019
README.md Transfer repository to HM organization May 2, 2019
asset-loader.php Tag v0.3.2 Jul 8, 2019
composer.json
composer.lock Fix `composer.json` for use as a packge. May 2, 2019

README.md

Asset Loader

This plugin exposes functions which may be used within other WordPress themes or plugins to aid in detecting and loading assets generated by Webpack, including those served from local webpack-dev-server instances.

Build Status

Usage

Full documentation to come. See react-wp-scripts for directional inspiration about how the methods in plugin.php may be used.

Assuming a Webpack configuration (such as those created with the presets in @humanmade/webpack-helpers) which sets up a Webpack DevServer instance for an entrypoint named editor.js, and assuming the asset manifest and the build, production version of the editor.js file would both end up in a build/ folder within a theme or plugin, you may load the bundle by using the Asset Loader's autoloader method:

<?php
namespace My_Plugin_Or_Theme;

use Asset_Loader;

add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_block_editor_assets' );

/**
 * Enqueue the JS and CSS for blocks in the editor.
 *
 * @return void
 */
function enqueue_block_editor_assets() {
  Asset_Loader\autoenqueue(
    // In a plugin, this would be `plugin_dir_path( __FILE__ )` or similar.
    get_stylesheet_directory() . '/build/asset-manifest.json',
    // The output filename of the Webpack build.
    // At present this must be consistent between development & production builds.
    'editor.js',
    [
      'scripts' => [ 'wp-element', 'wp-editor' ],
      'handle'  => 'optional-manually-specified-script-handle',
    ]
  );
}

License

This plugin is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

You can’t perform that action at this time.