webpack icon indicating copy to clipboard operation
webpack copied to clipboard

Adds a runtime variable __webpack_require__.dp to generate a dynamic path

Open arkapratimc opened this issue 10 months ago • 8 comments

fixes #18895

What kind of change does this PR introduce? It just introduces one variable __webpack_require__.dp which generates a dynamic path. Users can write __webpack_dynamic_public_path__ = (filename, publicPath) => .... to generate too.

Did you add tests for your changes? Yes

Does this PR introduce a breaking change? No

What needs to be documented once your changes are merged? A note of what __webpack_dynamic_public_path__ does in https://webpack.js.org/api/module-variables/

arkapratimc avatar Feb 16 '25 11:02 arkapratimc

Hey @alexander-akait , I just have one question, what’d be the signature of the function of __webpack_public_path__ ? For example, will it be like this →

__webpack_public_path__ = (filename) => "hey/" + filename;

arkapratimc avatar Apr 20 '25 11:04 arkapratimc

@arkapratimc Yes, you are right

alexander-akait avatar Apr 21 '25 11:04 alexander-akait

Does this work for chunk loading?

Jack-Works avatar Apr 23 '25 12:04 Jack-Works

@Jack-Works no, missing in this PR, anyway it is just __webpack_public_path__ improvement, in the original issue we need to allow define custom public path function in build time, not runtime

alexander-akait avatar Apr 23 '25 12:04 alexander-akait

hey @alexander-akait, test passes on one ubuntu machine https://dev.azure.com/webpack/webpack/_build/results?buildId=20771&view=logs&j=059dd913-30b4-5dab-74c6-1d726b9b84c8&t=0f11fa17-217a-5071-18f9-b54ec876c796&l=54 , but fails on another https://github.com/webpack/webpack/actions/runs/14623185311/job/41028317052?pr=19238#step:12:8 . Any idea on whats causing this ?

arkapratimc avatar Apr 24 '25 13:04 arkapratimc

hey @alexander-akait, test passes on one ubuntu machine dev.azure.com/webpack/webpack/_build/results?buildId=20771&view=logs&j=059dd913-30b4-5dab-74c6-1d726b9b84c8&t=0f11fa17-217a-5071-18f9-b54ec876c796&l=54 , but fails on another webpack/webpack/actions/runs/14623185311/job/41028317052?pr=19238#step:12:8 . Any idea on whats causing this ?

You need check the filename type. It can be { expr: string }. So the stringified (${filename}) result will be [object Object].

hai-x avatar May 03 '25 06:05 hai-x

CodSpeed Performance Report

Merging #19238 will not alter performance

Comparing arkapratimc:issue-18895 (1863436) with main (ebeace3)

Summary

✅ 33 untouched benchmarks
🆕 12 new benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 benchmark "future-defaults", scenario '{"name":"mode-development","mode":"development"}' N/A 286.1 ms N/A
🆕 benchmark "future-defaults", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' N/A 34.9 ms N/A
🆕 benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' N/A 2.4 s N/A
🆕 benchmark "many-chunks-commonjs", scenario '{"name":"mode-development","mode":"development"}' N/A 220.7 ms N/A
🆕 benchmark "many-chunks-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' N/A 42.8 ms N/A
🆕 benchmark "many-chunks-commonjs", scenario '{"name":"mode-production","mode":"production"}' N/A 1.9 s N/A
🆕 benchmark "many-chunks-esm", scenario '{"name":"mode-development","mode":"development"}' N/A 213.8 ms N/A
🆕 benchmark "many-chunks-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' N/A 42.1 ms N/A
🆕 benchmark "many-chunks-esm", scenario '{"name":"mode-production","mode":"production"}' N/A 2.2 s N/A
🆕 benchmark "typescript-long", scenario '{"name":"mode-development","mode":"development"}' N/A 30.9 s N/A
🆕 benchmark "typescript-long", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' N/A 27.7 ms N/A
🆕 benchmark "typescript-long", scenario '{"name":"mode-production","mode":"production"}' N/A 30.9 s N/A

codspeed-hq[bot] avatar May 03 '25 12:05 codspeed-hq[bot]

@hai-x hi, thanks, done - https://github.com/webpack/webpack/pull/19238/files#diff-07626cfb7da83ee25692aef62aec9dc6a32d6f0511b00e6b342121c5a87b5c75R596

Tests on the same machine are still failing ... (1) https://dev.azure.com/webpack/webpack/_build/results?buildId=20859&view=logs&j=059dd913-30b4-5dab-74c6-1d726b9b84c8&t=0f11fa17-217a-5071-18f9-b54ec876c796&l=54 (2) https://github.com/webpack/webpack/actions/runs/14811503127/job/41586744979?pr=19238#step:12:8

do you think, that making a separate PR can solve this, since it was created 3 months ago ?

arkapratimc avatar May 03 '25 14:05 arkapratimc