Roots Discourse

Sage 10 and custom admin.js

I’m using the newer release of Sage 10. I’m in the process of setting up a custom admin.js. I added it to laravel mix and it appears to be successfully rendering on save. It also looks to be enqueued to the admin.

I grabbed the boilerplate from editor.js and added a console.log to confirm everything is working. I’m having a hard time figuring out why it won’t fire. Anyone have any suggestions?

admin.js

import domReady from '@wordpress/dom-ready'

domReady(() => {
	console.log('admin js loaded')
})

Thanks!

Do you get the same result if you reduce this to an even more simplistic use case, i.e. remove the domReady wrapper and just run console.log('admin js loaded')?

Here’s the reduced version and it’s output:

I figured it out. I needed to include the vendor and manifest in ‘admin_enqueue_scripts’

/**
         * Enqueue admin js
         */
        add_action('admin_enqueue_scripts', function() {
            
            /* must include these! */
            wp_enqueue_script('sage/vendor.js', asset('scripts/vendor.js')->uri(), ['jquery'], null, true);
            wp_add_inline_script('sage/vendor.js', asset('scripts/manifest.js')->contents(), 'before');
            
            /* admin js now working */
            wp_enqueue_script('sage/admin.js', asset('scripts/admin.js')->uri(), ['sage/vendor.js'], null, false);

        });
1 Like