[英]JQuery HoverIntent not working with Webpack and the ProvidePlugin
I have the following... 我有以下......
webpack.config.js webpack.config.js
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
...
}),
deps.ts deps.ts
require('jquery-hoverintent/jquery.hoverIntent.js');
test.coffee test.coffee
$('.item').hoverIntent
over: ->
console.log("The hover is working");
When I run the application I get... 当我运行应用程序时,我得到...
$(...).hoverIntent is not a function
Can someone see what I am missing? 有人能看到我失踪的东西吗?
Update 更新
In jquery.hoverIntent I notice that it is taking the AMD path here... 在jquery.hoverIntent中我注意到它在这里采用AMD路径...
(function(factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define(function () {
return factory // Taking this path
});
} else if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = factory;
} else if (jQuery && !jQuery.fn.hoverIntent) {
factory(jQuery);
}
})(function($) {
'use strict';
if ($.fn.hoverIntent) {
return;
}
...
})
So I tried this in my typescript... 所以我在我的打字稿中尝试了这个...
var test = require('jquery-hoverintent');
test(window['$']);
But when I run in the factory function $
is undefined despite window['$']
being valid... 但是当我在工厂运行函数时,尽管
window['$']
有效,但$
is undefined ...
> $
undefined
> window['$']
$(selector, [startNode]) { [Command Line API] }
Update 2 更新2
This seems to work, however, I thought this was what the plugin was doing as well... 这似乎有效,但是,我认为这也是插件正在做的事情......
window['$'] = window['jQuery'] = require('jquery');
...
require('jquery-hoverintent')(window['$']);
So why does that work and not using the Provide Plugin. 那么为什么这样做而不使用Provide Plugin。
As you stated, hoverIntent doesn't use proper a proper amd-style definition, and therefore an extra step is needed when including it in webpack. 正如您所说,hoverIntent没有使用正确的amd样式定义,因此在将其包含在webpack中时需要额外的步骤。 It doesn't need the Provide plugin or need to use jquery attached to the window, however.
但是,它不需要Provide插件或需要使用附加到窗口的jquery。 I was able to get it to work with:
我能够使用它:
var $ = require('jquery');
require('jquery-hoverintent')($);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.