Skip to content

feat: accept empty string in config.resolve.extensions#12613

Merged
sokra merged 2 commits intowebpack:masterfrom
iguessitsokay:resolve-extensions-minlength
Apr 19, 2021
Merged

feat: accept empty string in config.resolve.extensions#12613
sokra merged 2 commits intowebpack:masterfrom
iguessitsokay:resolve-extensions-minlength

Conversation

@iguessitsokay
Copy link
Copy Markdown
Contributor

  • remove minLength from extensions in schema/WebpackOptions
  • add tests reflecting the change
  • no conflicts with existing tests
  • no conflicts with enhanced-resolve

Current behavior:
There is no way to determine the order of resolve attempts between the original request and appending extensions.

Expected behavior:
Adding an empty string to extensions sets the order of resolve attempt for the original request. This is only beneficial when used together with enforceExtension: true to pass the default intial resolve attempt.

Arguments:

  • minLength setting is unnecessary as is. resolve.extensions is consumed by AppendPlugin which is indifferent to string length.
  • More flexibility when using extensionless filenames.
  • When doing extensionless module requests, prioritizing the most prevalent extension (e.g. [".js", ""]) saves from unnecessary file -> final-file resolve steps, without giving up the ability to resolve the original request when necessary.

What kind of change does this PR introduce?

feature

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?

In resolve.extensions: Adding an empty string to extensions (e.g. [".js", ""]), determines the order of resolve attempt for the original request. By default resolver tries the original request before adding extensions; this initial attempt can be skipped by setting enforceExtension: true.

@webpack-bot
Copy link
Copy Markdown
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

Copy link
Copy Markdown
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

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

Ok we can do that, but in this case I would like that enforceExtension defaults to true when extensions contains an empty string.

@webpack-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@iguessitsokay
Copy link
Copy Markdown
Contributor Author

Thanks @sokra, that's great.
I made a pull request in enhanced-resolve for that:
webpack/enhanced-resolve#285

iguessitsokay and others added 2 commits April 19, 2021 11:45
- remove minLength from extensions in schema/WebpackOptions
- add tests reflecting the change
- no conflicts with existing tests
- no conflicts with enhanced-resolve
@sokra sokra merged commit 4c55729 into webpack:master Apr 19, 2021
@sokra
Copy link
Copy Markdown
Member

sokra commented Apr 19, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants