Skip to content

Instantly share code, notes, and snippets.

@fuchao2012
Created November 8, 2017 05:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
great export function
exports = module.exports = webpack
const exportsFn = (obj, mappings)=>{
Object.keys(mappings).forEach(prop=>{
Object.defineProperty(obj, prop, {
configurable: false,
enumerable: true,
get: mappings[prop]
})
})
}
exportsFn(exports, {
"module1": ()=>require('path/to/module1'),
"module2": ()=>require('path/to/module2'),
"module3": ()=>require('path/to/module3'),
"module4": ()=>require('path/to/module4'),
"module5": ()=>require('path/to/module5'),
"module6": ()=>require('path/to/module6'),
"module7": ()=>require('path/to/module7'),
"module8": ()=>require('path/to/module8'),
"module9": ()=>require('path/to/module9'),
"module10": ()=>require('path/to/module10'),
"module11": ()=>require('path/to/module11')
})
// output as
const module1 = require('path/to/module1')
module.exports = module1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment