question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying URL for various assets, not just chunks

See original GitHub issue

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

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
5punkcommented, 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!

1reaction
agoldiscommented, Mar 11, 2019

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL assets bundling · Issue #795 · evanw/esbuild - GitHub
When in a JavaScript file, a call to the global URL constructor whose first argument can be evaluated to a path at build...
Read more >
Asset Modules - webpack
asset /resource emits a separate file and exports the URL. Previously achievable by using file-loader . asset/inline exports a data URI of the...
Read more >
Conflict: Multiple assets emit to the same filename
If your configuration creates more than a single “chunk” (as with multiple entry points or when using plugins like CommonsChunkPlugin), ...
Read more >
About assets - Google Ads Help
For that reason, it's a good idea to use all the assets relevant to your ... Google Ads charges no more than two...
Read more >
Getting started with embargoed assets | Contentful
Why rewrite and use an asset service at all? Why not sign the URLs immediately in the content service and return them to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found