Sage 10, bootstrap is not known as an enqueued script

Hey,

I am new here and I am new to sage. I have many years of experience with wordpress plugins and theming, but not a lot with “modern web development standards”. I worked a bit with lavarel lumen before, and when I got into a new wordpress theme project I found Sage 10 and wanted to give it a shot. I like it a lot, but I still got to learn the ropes of how this works.

I have researched a bit on this but didn’t find a solution, so I post it into this board… feel free to point me to an answer if one exists already :slight_smile:

So I ran into the issue where I have another plugin that requires bootstrap without loading it by itself, but lists it in its dependencies.

*wp_register_script( 'daterangepicker', plugins_url( 'js/daterangepicker.js', __FILE__ ), array( 'jquery', 'bootstrap', 'moment' ), '3.1', true );*

The old theme has bootstrap registered and enqueued via wp_register_script(‘bootstrap’…), so the plugin picks it up and all works fine.

The problem is, that as I understood, Sage registers one single vendors.js file in the setup.php:

    *wp_enqueue_script('sage/vendor.js', asset('scripts/vendor.js')->uri(), ['jquery'], null, true);*

And then it imports bootstrap in the app.js:

*
import 'jquery';
import 'bootstrap';*

But the external plugin doesn’t pick that up, so it won’t enqueue its own script.

For a test i just changed the script name in the setup, this seems to work:

*wp_enqueue_script('bootstrap', asset('scripts/vendor.js')->uri(), ['jquery'], null, true);*

But I guess this is not a sustainable solution, also ideally since I wanna use more external scripts, I want to understand if there is a way to register the scripts, but then still load them in the vendor.js to minify them

or would it be smarter to go the other way around and enqueue all these scripts seperately and add them to the mix configuration to minify them on production?

UPDATE: I found a quick solution, which is simply to register bootstrap as an empty handle. Not sure if this is a best practice, but it works for now… Still happy to get better ideas, eg is there a way to automatically register scripts that are imported into the vendor.js?

    //TODO: This is a quick fix to register bootstrap for the vp-api plugin
wp_register_script('bootstrap', false);

This topic was automatically closed after 42 days. New replies are no longer allowed.