If you have a CommonJS module that exposes properties that are expensive to create (e.g. other CommonJS modules or some external resource), you can load them lazy using Object.defineProperty()
.
Last active
December 16, 2015 21:39
-
-
Save FokkeZB/5501314 to your computer and use it in GitHub Desktop.
Lazy exporting expensive properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In-expensive property | |
exports.foo = 'bar'; | |
// Expensive property | |
var propertyName; | |
Object.defineProperty(exports, "propertyName", { | |
get: function() { | |
return propertyName = propertyName || require('someOtherModule'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment