Many answers here on StackExchange and in documentation around the Internet indicate that to include a custom JavaScript file in a Magento 2 store that you should create a requirejs-config.js
to specify a file alias that you will then separately reference to require it.
For example, you might have this requirejs-config.js
file:
var config = {
map: {
'*': {
myscript: 'My_Module/js/myscript',
}
}
};
And this in your PHTML:
<script type="text/javascript">
require(['myscript'], function($) {
// optional loaded callback here
});
</script>
This works, but the question is:
Are both steps really necessary to include the JavaScript file?
requirejs-config.js
isn't really needed in case others wonder that in the future. If you have the access (I don't), please remove that duplicate question suggestion from this.requirejs-config.php
is needed. Your answer on the other question implies it is needed, when it's not.