Reputation: 90
I am trying to build my own jQuery plugin. Ik looks as follows:
(function ( $ ) {
$.fn.greenify = function() {
this.css( "color", "green" );
return this;
};
}(jQuery));
However, when trying to run this plugin, the error:
jQuery is not defined
My app.js looks as the following:
import $ from 'jquery';
global.$ = global.jQuery = $;
import './greenify';
Can anybody help on why this is happening?
The issue was that it couldn't find jQuery. Wat fixed the issue was instead of
}(jQuery));
to type
}(global.jQuery));
And instead of import './greenify'; do:
require('./greenify');
Upvotes: 1
Views: 295
Reputation: 7696
This is happening because you are importing $
variable try to changing to
(function ( $ ) {
$.fn.greenify = function() {
this.css( "color", "green" );
return this;
};
}($));
Upvotes: 1