https://github.com/humanmade/asset-loader
PHP utilities for WordPress to aid including dynamic Webpack-generated assets in themes or plugins.
https://github.com/humanmade/asset-loader
Last synced: about 1 year ago
JSON representation
PHP utilities for WordPress to aid including dynamic Webpack-generated assets in themes or plugins.
- Host: GitHub
- URL: https://github.com/humanmade/asset-loader
- Owner: humanmade
- License: other
- Created: 2019-04-08T03:23:35.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T15:43:13.000Z (over 1 year ago)
- Last Synced: 2025-06-14T08:11:57.641Z (about 1 year ago)
- Language: PHP
- Homepage: https://humanmade.github.io/asset-loader/
- Size: 226 KB
- Stars: 28
- Watchers: 17
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
# 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.
[](https://travis-ci.com/humanmade/asset-loader)
## Usage
This library is designed to work in conjunction with a Webpack configuration (such as those created with the presets in [@humanmade/webpack-helpers](https://github.com/humanmade/webpack-helpers)) which generate an asset manifest file. This manifest associates asset bundle names with either URIs pointing to asset bundles on a running DevServer instance, or else local file paths on disk.
`Asset_Loader` provides a set of methods for reading in this manifest file and registering a specific resource within it to load within your WordPress website. The primary public interface provided by this plugin is a pair of methods, `Asset_Loader\register_asset()` and `Asset_Loader\enqueue_asset()`. To register a manifest asset call one of these methods inside actions like `wp_enqueue_scripts` or `enqueue_block_editor_assets`, in the same manner you would have called the standard WordPress `wp_register_script` or `wp_enqueue_style` functions.
```php
'optional-custom-script-handle',
'dependencies' => [ 'wp-element', 'wp-editor' ],
]
);
Asset_Loader\enqueue_asset(
// In a plugin, this would be `plugin_dir_path( __FILE__ )` or similar.
get_stylesheet_directory() . '/build/asset-manifest.json',
// Enqueue CSS for the editor.
'editor.css',
[
'handle' => 'custom-style-handle',
'dependencies' => [ 'some-style-dependency' ],
]
);
}
```
## Documentation
For complete documentation, including contributing process, visit the [docs site](https://humanmade.github.io/asset-loader/).
## License
This plugin is free software. You can redistribute it and/or modify it under the terms of the [GNU General Public License](LICENSE) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.