We need to update our docs to reflect the changes made to enqueuing assets when we switched over to using Bud earlier this week, but…
wp_localize_script
needs to reference the handle of the enqueued asset. As of right now, app.js
is built and enqueued with the handle app/1
. To add a JS object to the app bundle, you’d do:
wp_localize_script('app/1', 'example', ['hello' => 'world']);
The result:
<script id='app/1-js-extra'>
var example = {"hello":"world"};
</script>
<script src='http://example.test/app/themes/sage/public/app.8bd132.js' id='app/1-js'></script>