When require.context
of webpack is assigned to variable,
how this variable can work receiveing parameter
, like 'key'?
For example,(in webpack document)
var context = require.context('components', true, /\.html$/);
// this 'context' variable receive parameter 'localA'
var context = require.context('locales', true, /\.json$/, 'lazy');
context('localeA').then((locale) => {
// do something with locale
});
In this code,
I can't understand why context
variable can receive parameter
'localeA'.
I looked in webpack documents, but I couldn't find how variable which is assigned to require.context
can receive the parameter.
See another example...
var req = require.context("../someDir", true, /^(.*\.(js$))[^.]*$/igm);
req.keys().forEach(function(key){
req(key);
});
// or just: req.keys().forEach(req)
webpack require every file in directory
the var req
already returned context
which fits conditions specified in parameters.
then, why this code recall 'req(key)' with 'key' parameter which represents element of array(context) agian?
Does this code mean => require.context(element of context = each file)?
I can't understand this recall either..
- In summary, my question is..
- How variable which is assignd to
require.context
can accept parameter. in webpack document,require.context
can accept 4 parameter, =>
require.context(
(directory: String),
(includeSubdirs: Boolean) /* optional, default true */,
(filter: RegExp) /* optional, default /^\.\/.*$/, any file */,
(mode: String) /* optional, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', default 'sync' */
);
but in the conde i can't understand,
the parameter which is sent to variable(is assigned to 'require.context') is key (element of context array)
- why they recall
require.cnotext
inrequire.context.keys().foreach()
,var req = require.context()
already returned context array(files fit conditions),then why this code repeats require.context(key) in foreach() block?
var req = require.context("../someDir", true, /^(.*\.(js$))[^.]*$/igm);
// => return context array
req.keys().forEach(function(key){
req(key);
// => means 'require.context(key)?
// why repeat require.context(each file)?
});
// or just: req.keys().forEach(req)
Please help me to understand this..