Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
Created January 24, 2017 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmawhorter/33e2c9d305ca4b4b910a5f366089cb2a to your computer and use it in GitHub Desktop.
Save cmawhorter/33e2c9d305ca4b4b910a5f366089cb2a to your computer and use it in GitHub Desktop.
rollup lazy top scope for node deps thoughts
let nodeDeps = {};
let nodeCache = {};
// some dependency
Object.defineProperty(nodeDeps, 'some_module', {
get: () => {
if (process.argv[2] !== 'hello') throw new Error('hello must be first argument');
const nodeModule = nodeCache.some_module || { world: () => console.log('world') };
return nodeModule;
}
});
// e.g. src/main.js
nodeDeps.some_module.world();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment