Open arthot opened 7 years ago
Has anyone got this working with webpack?
I'm bringing in the global $
dependency via the imports-loader:
import "imports-loader?$=jquery!air-datepicker/src/js/datepicker.js";
but then encountering another error on line:
this.views[this.currentView] = new $.fn.datepicker.Body(this, this.currentView, this.opts);
error: TypeError: $.fn.datepicker.Body is not a constructor
Which seems to me a bit of a chicken-egg situation, where I can import a global instance of jquery, but the library is referring to itself from the global jquery instance?
@oller, I suppose you should check your webpack configuration, because this is enough to get the plug-in workable with webpack:
"air-datepicker": "^2.2.3",
import $ from 'jquery';
import 'air-datepicker';
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
window.jQuery": "jquery"
})
HI, I suppose nowadays plug-ins just have to provide UMD, but this one does not. Should be quite simple change, because you already have
wrap
gulp pipe. Just need to extend most probably to this https://github.com/umdjs/umd/blob/master/templates/jqueryPlugin.jsWhy UMD? because for now this code will not work:
because
air-datepicker
rely on global $, which of course does not exist in any bundler such as Webpack, Browserify without "define" plugin. And that add some extra work especially when all others jquery plugins in project do have UMD )