t1m0n / air-datepicker

Lightweight, dependency-free JavaScript datepicker.
https://air-datepicker.com
MIT License
2.62k stars 1.37k forks source link

UMD #211

Open arthot opened 7 years ago

arthot commented 7 years ago

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.js

Why UMD? because for now this code will not work:

import $ from 'jquery'
import 'air-datepicker'

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 )

oller commented 6 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?

arthot commented 6 years ago

@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"
})