Skip to content

Instantly share code, notes, and snippets.

@victorwpbastos
Last active November 12, 2015 03:00
Show Gist options
  • Save victorwpbastos/43f3ba0cd1a85b436972 to your computer and use it in GitHub Desktop.
Save victorwpbastos/43f3ba0cd1a85b436972 to your computer and use it in GitHub Desktop.
Read all files in a dir with webpack
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