Skip to content
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

Modifying URL for various assets, not just chunks #8

Open
daihere1993 opened this issue Jul 9, 2018 · 9 comments
Open

Modifying URL for various assets, not just chunks #8

daihere1993 opened this issue Jul 9, 2018 · 9 comments

Comments

@daihere1993
Copy link

I want allot different CND for different chunk by their chunk name.

But I can't found any arguments in methodName( ) .

@daihere1993 daihere1993 changed the title methodName method don't have any arguments ? methodName( ) method don't have any arguments ? Jul 9, 2018
@agoldis agoldis self-assigned this Jul 9, 2018
@agoldis
Copy link
Owner

agoldis commented Jul 9, 2018

methodName doesn't have any arguments. You can use replaceSrcMethodName for that.

@5punk
Copy link

5punk commented Nov 2, 2018

@agoldis
Thanks for an amazing job on the plugin.
But, I feel this issue should be reopened.

replaceSrcMethodName adds a wrapper around the method: __webpack_require__.e = the chunk ensure function. This solves for webpack chunks.

For all bundle assets: Typically, __webpack_require__.p = the bundle public path. This will solve for css, images and javascript, set a contextual basehref. methodName already sets this.

This can only be done if you supply an argument to the methodName function, so developers can add a search and replace url functionality.

@agoldis
Copy link
Owner

agoldis commented Nov 2, 2018

@5punk I see your point, make sense!
Please reopen and describe your use-case in details - what is desired result and why existing tools cannot achieve the desired result. that would be very helpful for getting the issues resolved!

@agoldis agoldis reopened this Nov 5, 2018
@5punk
Copy link

5punk commented Nov 7, 2018

Absolutely.
Would you like me to submit a pull request too?

@agoldis
Copy link
Owner

agoldis commented Nov 7, 2018

@5punk If you have a solution - that would be awesome!!!

@agoldis
Copy link
Owner

agoldis commented Nov 19, 2018

@5punk hey, I was looking again into the issue and invested some time into trying to find a way to resolve it. I believe you want to obtain the path of imported resource as an argument to methodName().

So methodName() is invoked whenever __webpack_public_path__ is used at runtime.
The problem is that __webpack_public_path__ might be accessed by any plugin, for example, file-loader uses the following when it detects url('assets/bird.jpg') CSS syntax:

  var publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;

So, I there's no way to know would be the full required path.

Another approach would tweak the network layer (in a manner similar to replaceSrcMethodName), but it also seems not feasible because not all network requests are issued by using webpack (e.g. css url(....))

I can advise to use specific module / loader capabilities for manipulating the URL of a resource. E.g. https://github.com/webpack-contrib/file-loader#publicpath can be function that accepts resource name. Keep in ming, though, that the methods you provide is only invoked at build time.

If you have any suggestion / idea please share :)

@5punk
Copy link

5punk commented Dec 14, 2018

I spent some time looking and digging through webpack itself.
I can't find any hook or tapable event we can plug into that's a universal overridable fn callback.

The whole purpose is to have some baseref dynamically set. Where chunks from different cdn sources can be supported simultaneously.
If any plugin is close to solving the problem, it's this one.

I'm going to spend some time on gitter with the nice folk of webpack, see what we can brainstorm!

@agoldis agoldis changed the title methodName( ) method don't have any arguments ? Modifying URL for various assets, not just chunks Mar 10, 2019
@agoldis agoldis removed their assignment Mar 22, 2021
@orballo
Copy link

orballo commented May 20, 2022

Hi there,

Has there been progress on this issue? I'm trying this plugin, and I see that the chunks are using the correct publicPath, but images do not.

Is there a way to make this work?

Thanks!

EDIT: We are using Webpack 4. Would this issue be fixed if we update to Webpack 5?

@agoldis
Copy link
Owner

agoldis commented May 25, 2022

@orballo no progress unfortunately :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants