Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
Loading
from

Conversation

arkapratimc
Copy link
Contributor

@arkapratimc arkapratimc commented Feb 16, 2025

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/

adds a runtime variable __webpack_require__.dp to generate a dynamic path
@TheLarkInn TheLarkInn requested a review from Copilot February 18, 2025 19:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 11 changed files in this pull request and generated no comments.

Files not reviewed (5)
  • test/configCases/asset-url/dynamic/index.css: Language not supported
  • lib/asset/AssetGenerator.js: Evaluated as low risk
  • lib/RuntimeTemplate.js: Evaluated as low risk
  • eslint.config.js: Evaluated as low risk
  • lib/APIPlugin.js: Evaluated as low risk
Comments suppressed due to low confidence (2)

test/configCases/asset-url/dynamic/index.js:2

  • The test case should include scenarios where webpack_dynamic_public_path is not defined to ensure fallback behavior is correctly handled.
__webpack_dynamic_public_path__ = (filename, publicPath) => publicPath + "hey/" + filename

lib/RuntimeGlobals.js:392

  • [nitpick] The variable name dynamicPublicPath should be reviewed for consistency and clarity. Consider renaming it to something more descriptive.
module.exports.dynamicPublicPath = "__webpack_require__.dp";

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that is a wrong solution. We need to allow developer provide own dynamic path for JS files, not just generate extra code.

Anyway we can accept this, but it requires to be __webpack_public_path__: string | function, because we already have __webpack_public_path__ and we don't need to introduce other things.

@arkapratimc
Copy link
Contributor Author

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;

@alexander-akait
Copy link
Member

@arkapratimc Yes, you are right

{ expr: RuntimeGlobals.publicPath },
filename
);
assetPath = runtimeTemplate.generatePublicPath(filename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do it every where we have RuntimeGlobals.publicPath

@Jack-Works
Copy link
Contributor

Does this work for chunk loading?

@alexander-akait
Copy link
Member

@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

@hai-x
Copy link
Member

hai-x commented May 3, 2025

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].

Copy link

codspeed-hq bot commented May 3, 2025

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

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

Successfully merging this pull request may close these issues.

Allow public path to be a function
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.