How correctly connect https://github.com/RobinHerbots/jquery.inputmask using requirejs? Method on official site documentation not correct.
I try make it like this
require-config.js
paths: {
...
inputmask: "/assets/vendor/jquery.inputmask/dist/inputmask/inputmask",
dependencyLib: "/assets/vendor/jquery.inputmask/dist/inputmask/dependencyLib",
jQueryInputmask: "/assets/vendor/jquery.inputmask/dist/inputmask/jquery.inputmask",
...
}
script.js
define('script', ['jquery', 'jQueryInputmask'], function ($) {
...
$obj.inputmask(
{
alias: 'currency',
rightAlign: false,
digits: 0
}
);
...
});
but it not work
Try with this code:
require.config({
paths: {
...
"jquery" : "../dist/jquery/jquery",
"jQueryInputmask" : "../dist/inputmask/jquery.inputmask",
"inputmask" : "../dist/inputmask/inputmask",
...
},
shim: {
jquery: {
exports: "$"
},
jQueryInputmask: {
deps: ["jquery", "inputmask"],
exports: "$"
},
)
define('script', ['jquery', 'jQueryInputmask'], function ($) {
...
$obj.inputmask(
{
alias: 'currency',
rightAlign: false,
digits: 0
}
);
...
});
In my project it works setting the shim:
shim: Configure the dependencies, exports, and custom initialization for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With