I may be misunderstanding #1389 but if I have this in config/webpack/environment.js:
const { environment } = require('@rails/webpacker');
const webpack = require('webpack');
environment.plugins.prepend(
'Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
);
module.exports = environment;
then I expect to have access to $ and jQuery globally, including in the console window. This isn't happening. If I add a debug statement to development.js I see that the plugin is being added:
#console.log(environment.plugins);
ConfigList [
{ key: 'ProvideJQuery',
value: ProvidePlugin { definitions: [Object] } },
{ key: 'Environment',
value: EnvironmentPlugin { keys: [Array], defaultValues: [Object] } },
{ key: 'CaseSensitivePaths',
value:
CaseSensitivePathsPlugin { options: {}, pathCache: {}, fsOperations: 0, primed: false } },
{ key: 'ExtractText',
value:
ExtractTextPlugin { filename: '[name]-[contenthash].css', id: 1, options: {} } },
{ key: 'Manifest', value: ManifestPlugin { opts: [Object] } } ]
But I have no $ or jQuery in the browser window. And while some jQuery-dependent packs work fine, others don't -- specifically I encounter this issue: OwlCarousel2/OwlCarousel2#2206
moduleis loaded automatically and theidentifieris filled with the exports of the loaded module
if I understand correctly global scope is not modified and $/jQuery could be accessible only inside a module, to make identifier available globally you could write something like window.$ = $ inside your application.js module
I think you're probably looking for the Expose Loader; not the ProvidePlugin.
Most helpful comment
ProvidePlugin
if I understand correctly global scope is not modified and
$/jQuerycould be accessible only inside a module, to make identifier available globally you could write something likewindow.$ = $inside yourapplication.jsmodule