问题描述
我正在尝试将 bootstrap-daterangepicker 与 Webpack 结合使用.在我的视图文件中,我有以下内容:
I'm trying to use bootstrap-daterangepicker with Webpack. In my view file I have the following:
define(function (require) {
require('bootstrap-daterangepicker');
$('#daterangepicker').daterangepicker({ ... });
});
在 webpack.config.js
中:
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
})
]
这导致 daterangepicker 不是函数
.我看过daterangepicker.js
,而且似乎 $.fn.daterangepicker
没有正确导出.我该怎么做?我试过使用 imports-loader
来强制导入 jQuery,但这没有帮助.
This results in daterangepicker is not a function
. I've taken a look at daterangepicker.js
, and it seems that $.fn.daterangepicker
is not exported correctly. How would I do this? I've tried using imports-loader
to force import jQuery, but that didn't help.
推荐答案
显然 bootstrap-daterangepicker
试图加载他自己的 jQuery.因此 $.fn.daterangepicker
在我的"jQuery 中不可用.我已经强制 bootstrap-daterangepicker
在 webpack.config.js 中包含我的 jQuery 这一行:
Apparently bootstrap-daterangepicker
tries to load his own jQuery. Therefore $.fn.daterangepicker
is not available in 'my' jQuery. I've forced bootstrap-daterangepicker
to include my jQuery with this line in webpack.config.js:
resolve: {
alias: {
'jquery': require.resolve('jquery'),
}
}
这篇关于使用 Webpack 公开 jquery 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!