I’m trying to wrap my head around how Sage 9 enqueues jQuery… I read in a previous thread that Sage “tricks” WP into thinking that jQuery is enqueued?
I see the enqueue script in setup.php and the import'jquery' in the main.js file, but jQuery is also listed as a dependency in package.json. How does the import work, and where does it import from? How does the WP version get enqueued, or does it? Does Sage enqueue both the Wordpress jQuery and compile the node version into main.js, loading it twice?
How is everything tied together exactly, and how does that change if Soil is enabled?
WordPress Core registers jQuery as an available library, so when you define it as a dependency it’s automatically enqueued. See the official documentation.
The externals configuration option provides a way of excluding dependencies from the output bundles. Instead, the created bundle relies on that dependency to be present in the consumer’s environment.
In other words, webpack is told to not bundle up jQuery, but import 'jquery' in main.js makes the jquery object/variable available to other things in main.js.
If jQuery is being enqueued by WP, and is also not bundled, is the import even necessary? Does it ever get used? And if it does, does it import from node_modules?
Good questions, but what have you tried so far to try and find the answers? Have you looked at any sort of documentation? This isn’t specific to Sage, so there are resources out there to help you wrap your head around these things