Allow public path to be a function
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 65.9k
- Forks
- 9.5k
- Avg merge
- 10h 40m
- Merged PRs (30d)
- 296
Description
Feature request
Allow the public path to be a function.
What is the expected behavior?
It should call the function everytime instead of +.
What is motivation or use case for adding/changing the behavior?
https://developer.chrome.com/docs/extensions/reference/manifest/web-accessible-resources
There is an option called "use_dynamic_url" in Chrome extension.
Normally, resources can be accessed via URLs like chrome-extension://odhaijconicohjickedigmojjmeblalp/my-file.js, but with this option on (this options improves security and privacy), it has to be chrome.runtime.getURL('my-file.js'), and the return URL becomes chrome-extension://21f06455-6875-452b-8132-01268c50ba0e/my-file.js where the UUID is random every time.
It will be easier to support this use case in a plugin (https://github.com/awesome-webextension/webpack-target-webextension/issues/47) if the public path can be a function.
How should this be implemented in your opinion?
Add a new webpack internal function:
__webpack__require__.xxx = function (path) {
if (typeof __webpack_require__.p == 'function') return __webpack_require__.p(path)
return __webpack_require.p + path
}
And replace all direct use of RuntimeGlobals.publicPath to call this helper function.
Are you willing to work on this yourself?
yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the webpack runtime uses of RuntimeGlobals.publicPath and identify every direct use that would need the proposed helper. Review the generated runtime behavior for both string and function public paths, then add or update tests covering repeated function calls and the existing string behavior. Done means dynamic URLs are supported without regressing normal public-path concatenation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100