I can’t find a way to specify script dependencies using the bud enqueuing method.
What I’d like to do, using
bundle('app')->enqueue();, is something equivalent to :
wp_enqueue_script( 'handle', '/my/script.js', ['jquery', 'wp-i18n'], '1.0.0' );
Any ideas ?
What would be the simplest way to add a dependency to app.js ? What I’d like to do is to load it after wp-l18n has loaded.
I assume I would have to remove
bundle('app')->enqueue() and replace it with some enqueueJs and enqueueCss combination ?
Have you tried that? Did you run into a problem?
@wordpress dependencies referenced in project scripts:
- are collected during compilation and flagged as dependencies of the entrypoint.
- are replaced by references to
You can see this for yourself by importing
app.js. You do not need to install
@wordpress/i18n – it’s replaced by the
const main = async () => null;
After running a build, check out
./public/entrypoints.json. You’ll see
wp-18n in the
dependencies array for the asset:
In the browser if you check out the
sources tab of devtools you’ll see that
i18n.min.js is loaded:
So, in short, you don’t need to do anything at all. It’s already done for you.
Thank you, this is what I was looking for !