Webpack - Require.context -how To Require All .js Files Except `_test.js` In A Directory?
My goal was to create a file that would Require all of the JS files in a directory that didn't end in _test.js Do a module.exports equal to an array of module names returned from
Solution 1:
Ok, I was able to use the answer in Slava.K's comment to answer my question. Here's the final code below. I had to include (?!.*index)
in the regex because this code was including itself index.views.js
.
var context = require.context('.', true, /^(?!.*index).*\/(?!.*test).*\.js$/);
var moduleNames = _.chain(context.keys())
.map(function(key) {
return context(key)
})
.value();
module.exports = angular.module('myApp.demoApp.views', moduleNames).name;
Post a Comment for "Webpack - Require.context -how To Require All .js Files Except `_test.js` In A Directory?"