feat: add context option support for VirtualUrlPlugin#20449
feat: add context option support for VirtualUrlPlugin#20449xiaoxiaojx wants to merge 4 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: ecaee86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (ecaee86). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@ecaee86
yarn add -D webpack@https://pkg.pr.new/webpack@ecaee86
pnpm add -D webpack@https://pkg.pr.new/webpack@ecaee86 |
7026dca to
9fe896a
Compare
| resourceData.context = virtualConfig.context; | ||
| } else { | ||
| resourceData.context = compiler.context; | ||
| } |
There was a problem hiding this comment.
let's allow only string context, by default - compiler.context, otherwise virtualConfig.context
There was a problem hiding this comment.
I’m curious why this isn’t true by default 🤔, like auto, where we automatically set the context for virtual modules. Since the virtual module ID and the context value are almost the same, it feels like setting the same value twice. I’d prefer to minimize users’ exposure to the context option unless there’s a very specific use case.
There was a problem hiding this comment.
I agree, that is why I think we don't need support function and true type, only string, also I don't think we need to check on undefined we by default use compiler.context
There was a problem hiding this comment.
Makes sense. For now, I’ve kept only the default value "auto". This avoids requiring users to configure the context option and also prevents configs from being cluttered with repeated "auto" values, like { mod1: { context: "auto", source() {} }, mod2: { context: "auto", source() {} }, mod3: { context: "auto", source() {} } }.
There was a problem hiding this comment.
I am afraid that it is a breaking change, auto is the new behavior, old virtual modules can be broken, right?
Do I understand correctly this feature, if I have /path/to/src/components/button.js, context will be path/to/src/components/?
There was a problem hiding this comment.
This won’t affect existing virtual modules. Previously, virtual module paths like "virtual:routes" were only used as unique IDs, and their context was always fixed to compiler.context. With context: "auto", for "virtual:routes" the computed context is still compiler.context, so nothing changes.
Now we’d like to extend virtual module paths so they’re not just IDs, but virtual paths with context information — for example, virtual:src/components/button.js. In that case, the context would be resolved to something like /path/to/src/components/button.js.
9fe896a to
f9153b5
Compare
f9153b5 to
0b2874a
Compare
Summary
Add
contextoption support for VirtualUrlPluginWhat kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Nothing