-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Requiring jquery-sticky in webpack not working #267
Comments
The Problem seems to be that the plugin relies on the global jquery variable $ to function properly and that it gets an instance of jQuery but not the global. So it binds itself not to the global jQuery object and is therefore not available there. |
I found a workaround with expose-loader: |
Any chance you could elaborate? @martinwittmann. I'm doing a migration to Webpack from Browserify on a Rails app and am blocked by jquery-sticky. Im trying to import jquery using providePlugin from webpack. but cannot get the sticky function at attach to the jquery object. Basically this stack overflow.. Thanks in advance. |
@martinwittmann, I was able to get jQuery and this library to work with the following: $ yarn add jquery-sticky # environment.js
const { environment } = require("@rails/webpacker")
const webpack = require("webpack")
environment.plugins.prepend(
"Provide",
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
sticky: "sticky",
})
)
const config = environment.toWebpackConfig()
config.resolve.alias = {
jquery: "jquery/src/jquery",
sticky: "jquery-sticky/jquery.sticky",
}
module.exports = environment # application.js
import {} from "sticky" |
When using
require('jquery-sticky);
in webpack jquery-sticky does not attach to the global jquery object.
Did I miss something or is this broken?
(I tried the solutions in the accepted answer of https://stackoverflow.com/questions/28969861/managing-jquery-plugin-dependency-in-webpack without success)
The text was updated successfully, but these errors were encountered: