esnunes / riotjs-loader

riotjs module loader for webpack
MIT License
103 stars 41 forks source link

How to get require.context working #4

Open danieltian opened 9 years ago

danieltian commented 9 years ago

Requiring tags files work properly if I use require('./tags/buddy-list.tag');. The JS output properly sets up a riot.tag(...). However, when I try to use require.context('./tags', true, /\.tag$/), what I get in the JS output is this instead:

var map = {
  "./baron-chat.tag": 13,
  "./buddy-list.tag": 14
};

It looks like the tags aren't getting compiled properly. Any idea how I can get require.context working?

danieltian commented 9 years ago

Figured it out:

var context = require.context('./tags');
context.keys().forEach(key => {
  context(key);
});

require.context returns an object where each key's value is a require() function.