I am trying to use Bootbox with RequireJS, but every time this error appears:
ReferenceError: bootbox is not defined
I configured RequireJS with the dependencies:
var
bowerLocal = "../../../bower_components/",
asstsLocal = "../../assets/";
requirejs.config({
paths: {
"jquery": bowerLocal + "jquery/dist/jquery.min",
"jquery.bootbox": bowerLocal + "bootbox/bootbox",
"jquery.bootstrap": bowerLocal + "bootstrap/dist/js/bootstrap.min",
"jquery.elevateZoom": bowerLocal + "elevatezoom/jquery.elevateZoom-2.2.3.min",
"jquery.maskedInput": bowerLocal + "jquery-maskedinput/dist/jquery.maskedinput.min"
},
/**
* Define as dependências de bibliotecas.
*/
shim: {
"jquery.bootstrap": {
deps: ["jquery"]
},
"jquery.elevateZoom": {
deps: ["jquery"]
},
"jquery.maskedInput": {
deps: ["jquery"]
},
"jquery.bootbox": {
deps: ["jquery", "jquery.bootstrap"],
exports: 'bootbox'
}
}
});
require(
["jquery", "jquery.bootstrap", "jquery.bootbox", "jquery.maskedInput", "jquery.elevateZoom"],
function (util) {
bootbox.alert("Hi");
}
...
bootbox is not defined on window in AMD mode, you have to define it yourself, so after doing the below it works now.
define(["bootbox"], function(bootbox){
bootbox.alert("Hello Bootbox");
});
Of course the path is defined in require.config()
, This will work.