Skip to content

docs: add docs for module condition#10524

Closed
benmccann wants to merge 1 commit intovitejs:mainfrom
benmccann:module-docs
Closed

docs: add docs for module condition#10524
benmccann wants to merge 1 commit intovitejs:mainfrom
benmccann:module-docs

Conversation

@benmccann
Copy link
Collaborator

Description

The module condition is not discussed in the Node docs, so I had a very hard time understanding what it was for. It seems to be something invented by Webpack which we later adopted

Additional context

Motivated by #10442 and #10495


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@benmccann benmccann added the documentation Improvements or additions to documentation label Oct 18, 2022
Here, `import` and `require` are "conditions". Conditions can be nested and should be specified from most specific to least specific.

Vite has a list of "allowed conditions" and will match the first condition that is in the allowed list. The default allowed conditions are: `import`, `module`, `browser`, `default`, and `production/development` based on current mode. The `resolve.conditions` config option allows specifying additional allowed conditions.
Vite has a list of "allowed conditions" and will match the first condition that is in the allowed list. The default allowed conditions are: `import`, [`module`](https://webpack.js.org/guides/package-exports/#providing-commonjs-and-esm-version-stateless), `browser`, `default`, and `production/development` based on current mode. The `resolve.conditions` config option allows specifying additional allowed conditions.
Copy link
Member

Choose a reason for hiding this comment

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

It looks like Vite doesn't follow the logic from the link. Webpack uses module for require() to prevent code duplication, but Vite would skip module for require(), and only works for import. Maybe we should remove the link for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm. I wonder if module is something we should support in that case then. Anyway, I'll go ahead and close this based on your feedback

@benmccann benmccann closed this Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments