Last active
November 12, 2015 03:00
-
-
Save victorwpbastos/43f3ba0cd1a85b436972 to your computer and use it in GitHub Desktop.
Read all files in a dir with webpack
This file contains 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
var _ = require('underscore'); | |
var paths = require.context('./models', true, /.js$/); | |
var models = []; | |
_(paths.keys()).each(function(path) { | |
var name = /.\/(.*).js/.exec(path)[1]; | |
models[name] = paths(path); | |
}); | |
var model = new models['a']({id: 123}); | |
console.log(model.get('name')); | |
console.log(model.get('id')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment