-
-
Notifications
You must be signed in to change notification settings - Fork 257
Allow publicPath handler to return a function instead of string #327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just the question - how you want to solve problem for other loader? I think we can solve this problem on webpack level? Can you provide simple example?
@evilebottnawi Can you elaborate the question? |
Because it is fix only logic for |
Well, I am not sure this can be solved on webpack level. |
We don't want add new option to file-loader, because in webpack@5 it was built-in loader, so we need solve this problem on webpack level to avoid same problems in future for other developers |
Okay no problem, we will just fork it. |
@prontiol why is hard to help other developers solve same problem? Is it hard to provide minimum reproducible test repo? Maybe we can same logic without modify source code |
It's not hard so I made this PR. It fixes the problem I encountered and can help others. Regarding the minimum reproducible repo: test case included in the PR is pretty much self-explanatory. |
Stop be toxic. I am open to feedback, unlike how you build a dialogue.
I said that I would not like to add, but if we do not find other solutions, it will be merged
Yes, but we need feedback from developers to solve problems and design right architecture to avoid problems in future (for loader and for webpack@5).
This does not mean that we should merge all PRs that are sent to us just because they are not breaking change
No, maybe you use invalid approach to storage or organization assets, maybe you need other setup for cdn, and many many cases in other way What i want? I want example where standard functionality not solve you problem with real life example. This will allow us to think how best to solve such problems now and in the future. |
I am no longer interested in contributing to this repo. |
This PR contains a:
Motivation / Use-Case
Sometimes you might need to construct the path to your assets in runtime (for example when using multi CDN for different types of assets). Currently the only way to change the base path is to update
__webpack_public_path__
and it will affect all the assets at once 😞If only we could have a function instead of plain string which will be executed in runtime and return the path based on the asset type, variables, cookies or whatever you want to figure out the right base path... oh wait, but we can!
This PR is to rescue! 🎉
Breaking Changes
No breaking changes.
Current implementation just produces nothing If you return a function instead of string out of the
options.publicPath
handler becauseJSON.stringify(function) === undefined
This PR enhances
file-loader
and now you can return a function which will be executed in runtime so you can enjoy all your variables and helper functions in it and construct a publicPath of your dream.