Skip to content

Instantly share code, notes, and snippets.

@josephg
Created May 12, 2016 00:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephg/581b73e95c48f7daecca413c4ee06b04 to your computer and use it in GitHub Desktop.
Save josephg/581b73e95c48f7daecca413c4ee06b04 to your computer and use it in GitHub Desktop.
Slow requires
var tree = require("terminal-tree");
const loadingData = [];
var current = loadingData;
global.wr = (_require) => {
return (name) => {
const start = Date.now();
const parent = current;
current = [];
const module = _require(name);
const time = Date.now() - start;
if (time > 20) {
parent.push(`${name} (${time}ms)`);
if (current.length > 0) parent.push(current);
}
current = parent;
return module;
}
};
const _require = wr(require);
var keystone = _require('keystone');
console.log(tree(loadingData, {
symbol: true,
highlight: true,
padding: 1
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment