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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -