Skip to content

Instantly share code, notes, and snippets.

@kirmorozov
Last active December 4, 2018 22:19
Show Gist options
  • Save kirmorozov/8a94f3afc33f693d133077ca3b028360 to your computer and use it in GitHub Desktop.
Save kirmorozov/8a94f3afc33f693d133077ca3b028360 to your computer and use it in GitHub Desktop.
Collect Magento 2 JS dependencies as directed graph
// Compatible with requirejs/alameda
let dependencies = Object.values(require.contexts._.deferreds).map((m) => {
if (m.hasOwnProperty('deps')) {
return m.deps.map((d) => {
return [m.map.id, d.id];
});
} else {
return [];
}
}).filter((x) => {return x.length > 0;} );
let merged = [].concat.apply([], dependencies);
let modules = [].concat.apply([], merged).filter((v, i, a) => a.indexOf(v) === i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment