Best thing to do is use a Magento 2 Module or a Theme to include such plugins/libraries. It is the recommended way and the best practice. Is there anything blocking you from doing that? If so, pls share.
Method 1 > THEME: If the javascript/jquery library is theme related (In order to change the look and feel of the system).
- Place the custom component source file in one of the following location
[theme_dir]/web/js/
- Place your requirejs-config.js file in
[theme_dir]
Method 2 > MODULE: If the javascript/jquery library is related to a particular business function or handles a Magento feature. It should go inside a module.
Magento 2 strongly recommends not changing the source code of default
Magento components and widgets. All customizations must be implemented
in custom modules or themes.
[EDITED: To provide a example as per in the first comment]
Using method 1 for including a js file.
File: [Root_Dir]/app/code/[NameSpace]/[Module]/view/frontend/requirejs-config.js
var config = {
map: {
'*': {
faq:'Namespace_Module/js/faq'
}
}
};
Then the file related to this mapping will be there on the same module directory.
File: [Root_Dir]/app/code/[NameSpace]/[Module]/view/frontend/web/js/faq.js
//faq.js
define([
"jquery"
], function ($) {
alert('TEST');
});
So the script path in the require-config.js file should be specified from modules view/frontend/web directory, without the .js extension.
This way, a script can be added to the frontend.
Follow the default module ./vendor/magento/module-checkout/*
or similar...
EDIT 2:
If you want to debug and see from where Magento is trying to pull the static file, follow the article on http://www.magleaks.com/magento-2-static-file-resolving/ and add a debug pointer to the file [DOC_ROOT]/vendor/magento/framework/View/Design/FileResolution/Fallback/Resolver/Simple.php