Closed nickdima closed 10 years ago
I like to have a API similar to this:
bundle?name=chunkName
bundle?name=view-[name]!...
bundle?regExp=([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$&name=abc-[1]-[2]
[name]
basename of this.resourcePath
[ext]
extension of this.resourcePath
[path]
dirname of this.resourcePath
[N]
match number N of query param regExp
as RegExp
Great suggestions! I'll see to it.
One thing. Is there some shared code already that I can use to parse the placeholders in name
?
.replace(/\[ext\]/ig, function() {
return ext;
}).replace(/\[name\]/ig, function() {
return basename;
}).replace(/\[path\]/ig, function() {
return directory;
});
One more thing, when you say [path]
dirname of this.resourcePath
you're referring to the parent directory, the full absolute path or a path relative to something else?
full absolute path...
what would be the use case for full absolute path in the chunk name?
hmm... yes, maybe the same approach as for the file-loader is more useful. In this case you could move the replacement code into loader-utils.interpolateName(loaderContext, nameQuery)
and use it from both, bundle-loader and file-loader.
Yes, it makes sense having a function in loader-utils
for other loaders to use it.
Just to make sure we're on the same page, the plan would be this: extract the interpolating functionality together with the hash options, add the RegExp feature and put it all in a function on loader-utils
.
yep...
interpolate(loaderContext, strToBeInterpolated, optionsObject)
optionsObject.content: content to be hashed... (from file-loader)
optionsObject.query: parsed query string. (for regExp, context, hash, digest, size)
@nickdima I'm just curious: Why do you need to set the file's name explicitly?
Well, it seems more cleaner for my use case.
I'm creating a chunk for each page defined in my router and it will be named something like page-home-d527af.js
It gives me the feeling that I have more control like this, in case I need to preload the most visited pages or maybe check at a glance which chunks weights more, etc.
Either one of these parameters is used for naming the chunk file. The
name
parameter is a simple string whilenameRegex
is a string containing a regular expression for extracting the name from the path of the file being required, especially useful for dynamic requires.