Find what global variables are used in js code.
For this module, a "global dependency" is a global variable used by your code that is not provided by the environment.
Maybe you want to find these and do something with webpack's imports-loader.
npm install find-global-deps
Requires node 6 or later
var findGlobalDeps = require('find-global-deps');
var code = 'let a = foo';
var result = findGlobalDeps(code);
result // Set { 'foo' }var findGlobalDeps = require('find-global-deps');Returns a Set<string> of names of global dependencies found.
String of js code.
Optional array of strings. Defaults to ['es6', 'browser'].
Specifies what environment code is written for. Any use of globals that come with these environments (e.g. process in node) will not be reported.
Can contain any top-level property names of the object exported by the globals module which are: builtin, es5, es6, browser, worker, node, commonjs, amd, serviceworker and more.
Examples
// node
findGlobalDeps(code, {
environment: ['es6', 'node']
});
// commonjs in browser
findGlobalDeps(code, {
environment: ['es6', 'browser', 'commonjs']
});Does not detect (yet)
window.fooin browserthis.fooat top level in browserglobal.fooin node
MIT