feat: added support for import.meta.dirname and import.meta.filename#20050
Merged
alexander-akait merged 9 commits intomainfrom Oct 28, 2025
Merged
feat: added support for import.meta.dirname and import.meta.filename#20050alexander-akait merged 9 commits intomainfrom
import.meta.dirname and import.meta.filename#20050alexander-akait merged 9 commits intomainfrom
Conversation
Contributor
|
This PR is packaged and the instant preview is available (6d02aea). Install it locally:
npm i -D https://pkg.pr.new/webpack@6d02aea
yarn add -D https://pkg.pr.new/webpack@6d02aea
pnpm add -D https://pkg.pr.new/webpack@6d02aea |
alexander-akait
commented
Oct 24, 2025
| .importMetaDirnameAndFilename | ||
| ) { | ||
| return true; | ||
| } |
Member
Author
There was a problem hiding this comment.
Don't replace import.meta.dirname and import.meta.filename when env supports them
alexander-akait
commented
Oct 24, 2025
| return true; | ||
| }); | ||
| } | ||
| break; |
Member
Author
There was a problem hiding this comment.
Prevent removing import.meta.filename
alexander-akait
commented
Oct 24, 2025
|
|
||
| return true; | ||
| }); | ||
| } |
Member
Author
There was a problem hiding this comment.
Prevent removing import.meta.dirname
alexander-akait
commented
Oct 24, 2025
| dirname, | ||
| (functionName) => | ||
| `${functionName}(${importMetaName}.url + "/..").slice(0, -1)` | ||
| `${functionName}(${importMetaName}.url.replace(/\\/(?:[^\\/]*)$/, ""))`, |
Member
Author
There was a problem hiding this comment.
Using regexp to replace the last /file.ext to get a right value for dirname
CodSpeed Performance ReportMerging #20050 will degrade performances by 10.17%Comparing Summary
Benchmarks breakdown
|
lib/NodeStuffPlugin.js
Outdated
| parser.hooks.expression | ||
| .for(expressionName) | ||
| .tap(PLUGIN_NAME, (expr) => { | ||
| .tap({ name: PLUGIN_NAME, stage: -100 }, (expr) => { |
Member
There was a problem hiding this comment.
for tap ordering, we should have a constant instead of hard-setting it to a value
This was referenced Nov 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Added support to
import.meta.dirnameandimport.meta.filenameAlso:
__dirnameor__filenamelocal variables (we use this names when get__dirnameand__filenamefromimport.meta.url), now we use__webpack_dirname__and__webpack_filename____dirnamefor ES modules has a right value, using../is not working to get dirname, now we use regexpfixes #19990
fixes #18320
What kind of change does this PR introduce?
feature and bugfixes
Did you add tests for your changes?
WIP
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?
Yes, we need to show that we handle
import.meta.dirnameandimport.meta.filename