javascript - Mysterious line, used to require html templates in Webpack: templates.keys().forEach(templates)? -


i want import html templates webpack bundle ngtemplate-loader , html-template-loader , found 2 lines of code, used purpose, in project:

const templates = require.context(__dirname, true, /\.html$/); templates.keys().foreach(templates); 

the first line clear me - recursively requires html files under current directory, adding them $templatecache.

but second line total mistery me. what's point of it?

templates.keys() return array of paths matched files:

['./file1.js', './file2.js'].foreach(templates); 

then foreach invoke templates function (which require context setted __dirname) each file:

templates('./file1.js'); templates('./file2.js'); 

or:

require('./file1.js'); // files searched relative __dirname require('./file2.js'); 

Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -