-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept a transforming function as an option #165
Comments
Thanks @bmancini42, now that Babel 7.0 will support a javascript file as a configuration file ( This can be tricky though. Let's say you have a root configuration. Do you want to apply a global transformation on the files matching it as well? Only for alias? Should we offer the ability to setup a global transform function, or only targeted one based on one alias? |
I was thinking that implementing pre- and post- hooks would be the solution to this problem, but maybe allowing the use of a custom {
plugins: [
['module-resolver', {
getRealPath(sourcePath, { file, getRealPath, opts }) {
// Implement your own getRealPath, possibly using the original method
}
}]
]
} |
Hmm... Yep, I'm not a huge fan of This lead me to think about what you said in another ticket @fatfisz... Should we execute the alias resolver on the root config? :D Let's say we provide the custom transform function. If the user specify a root config + function (if we allow this), should we run the fn on the root as well? What do you think? |
My thought was that it would take place whenever aliasing takes place -- after roots, I guess. If you think of alias as being a transform function that only applies a regex, this is a transform function that happens at the same time but allows you more freedom. |
If I understand correctly, you can do this pre-Babel 7 also, by using the |
Yes, Anyway, I believe it's good to provide a transform function and we could even go further and allow a string to a path, or a function. My only concern is to put that at the right place in the code. I'd say that the custom transform should replace everything (root and alias). I don't really know if offering the default root/alias transformers would make sense.. @fatfisz, any thoughts? |
I think that it should be either the |
@tleunen After #194 is merged we would be able to go forward with this like so:
|
It would be nice to have an additional option possibility for using a transforming function on the path. RegExs are suitable for most situations, but sometimes you want to have a smarter transformation.
In my case, I had been using a webpack resolver function to basically:
1 - Find a reserved string in the old path
2 - Replace the reserved string with a configured param
3 - If that transformed file exists, use it as the new path
4 - Otherwise, use a fallback path
This requires processing specific to each path, rather than just a simple transformation you could do with the same RegEx to all paths.
I happened on the idea of using this plugin to do this instead, since my ava tests were not using webpack's resolve plugin, but this would require that this plugin be extended to allow for a transforming function as an option.
cf #164
The text was updated successfully, but these errors were encountered: