-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack import $.my() is not a function. #31
Comments
I was actually misusing the expose-loader, removing the plugins block from my webpack config and appending, {
test: require.resolve('jquery'),
loaders: ['expose?$', 'expose?jQuery']
}, solved this issue. |
Nice! Can you please provide entire resulting config or whatever to help respond future questions of this kind? I have nearly zero experience with webpack, any information is valuable. Thanks ) |
yeah for sure man, in full disclosure i'm also just starting out with webpack so while this setup does work, I can't guarantee that it is the best, or recommended, approach. The following is using
as far as the config goes, (and from what I gather this applies to a large portion of jQuery plugins), assuming you have webpack setup in your project directory, you'll need the expose-loader, npm i expose-loader -D the rest of the configuration is unimportant, save for the part I mentioned before, as described on the expose-loader github page, you'll need to add the specific loader test (tells webpack when to use the loader) //webpack.config.js
module.exports = {
....
module: {
loaders: [
....
{
test: require.resolve('jquery'), //use this loader for jquery plugin
loaders: ['expose?$', 'expose?jQuery'] //expose this jquery to the global '$' and 'jQuery' vars.
},
....
]
}
....
}; That took care of all jqeury issues in my case. import 'sugar'; // require('sugar'); if not using ES6 In my main entry point, before any of my other imports/requires, this will resolve to the version of sugar installed automatically by npm when installing jquerymy. Webpack usually takes care of this stuff, I might have missed something, but anyways, this worked. If anyone with further insight into webpack has anything to share, please do, and I hope this helps someone in the future. |
You made perfect work, thanks!
I will look into it more deeply. |
Still grasping some fundamentels about webpack, but from what I gather plugin is not being applied on the global jquery? I've tried expose-loader and imports-loader approaches, and also have jquery on my ProvidePlugin object,
to no avail.
Can there be some instructions or suggested method of using this plugin with webpack in the docs?
The text was updated successfully, but these errors were encountered: