Remove JQuery?

I am new to Sage, and am enjoying it very much, especially the inclusion of Blade and the build speeds I am seeing.

Is there a straightforward way to remove JQuery? I am interested in doing most my tasks with vanilla JS.
I have tried removing the import in main.js, but am still seeing it included in the header.

I read this thread:


but I think I am missing something simple on how scripts are enqueued into the head.

Thanks.

Remove the usual WP way. Sage 9 does not include jQuery in main.js

add_filter('init', function () {
    if (is_admin()) {
        return;
    }

    wp_deregister_script('jquery');
    wp_register_script('jquery', false);
});
2 Likes

Great, thank you!
Am I correct in that registering new scripts are done within setup.php in this manner?

wp_enqueue_script('sage/custom_js', Assets\asset_path('scripts/custom.js'), ['sage/js'], null, true);

Looks correct to me, but I’ve had a beer. If it works, then yes.

2 Likes

try yarn remove jquery maybe ?

Can someone explain to me why I get ‘JQuery is not defined’ when applying this method?

Error messages:
module.exports = jQuery; (JQuery is not defined)

Seems to be a result of this call in main.js:

// Load Events
jQuery(document).ready(() => routes.loadEvents());

I would have thought the webpack config and the JQuery import in main.js would be all we need.

It’s not clear to me where this code exists in your project, but this post from a while ago might be relevant: How Does Sage 9 Enqueue jQuery?

Thanks. I’m pretty sure my error is from the default set up of a recent Sage 9 install. The only modification I am making are to filters.php (removing jquery) and setup.php (removing jquery as a dependency of main.js)

I guess I’ve got some reading to do!