I create the external js for magento 2 backend like this:
Namespace/Module/view/adminhtml/requirejs-config.js
:
var config = {
map: {
'*': {
regionsForm: 'Namespace_Module/js/regions-form'
}
}
};
in Namespace/Module/view/adminhtml/web/js/regions-form.js
define([
'jquery',
'underscore',
'mage/url',
'jquery/ui'
], function ($, _,urlBuilder) {
'use strict';
$(function() {
console.log('a');
});
});
i already delete pub/static and ran setup:upgrade & static:content, but when i inspect element in my browser i cant find my js file, but in pub/static my file is already there.
Edit:
I ran deploy command php bin/magento setup:static-content:deploy
Best Answer
The reason is that we didn't call the custom script. So, we can call it via template or the head. You can try two cases:
1) We can add directly on the head.
app/code/Namespace/Module/view/adminhtml/layout/default.xml
In this case, remember to change
define
torequire
in the custom script.2) We can call it via template:
app/code/Company/Module/view/adminhtml/templates/test.phtml