Skip to content

Comments

fix(css): always use css module content#8936

Merged
patak-dev merged 1 commit intovitejs:mainfrom
sapphi-red:fix/css-module-include
Jul 6, 2022
Merged

fix(css): always use css module content#8936
patak-dev merged 1 commit intovitejs:mainfrom
sapphi-red:fix/css-module-include

Conversation

@sapphi-red
Copy link
Member

Description

Unfortunately I failed to implement what I said at #8900 and ended up reverting #7591 (review). 😞

This will cause the following code not to be tree-shaked.

/* input */
import './foo.module.css' // note that default export is not used

/* output(old) */
// none

/* output(new) */
var foo_module_css = { foo: 'foo_hash' }

But because this code usually does not happen, I think it is not so bad.

Also this PR does not fix #8245 (comment).

For better or worse, this PR could be backported to v2 since this is a simple partial revert of #7591. I'll create it later if we are going this way.

fixes #8245
fixes #8461
refs #8874, #8896

Additional context

The fix I said at #8900 is to resolve id before injecting ?used.
But this faced to some issues:

  1. normalize.css will be normalize.css?used.
  2. #alias will be #alias?used.
    • This is not safe. #alias might be perfect matching like /^#alias$/. Replacing to #alias?used makes it not to be resolved.

We could use ${resolvedId}?used (/path/to/node_modules/normalize.css/normalize.css) instead. But if there is a exports field and normalize.css is not included, it will fail to resolve.


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.

@sapphi-red sapphi-red added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release labels Jul 5, 2022
@netlify
Copy link

netlify bot commented Jul 5, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit 0af3e0c
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62c46e017d2d7e0009c33863

@sapphi-red sapphi-red force-pushed the fix/css-module-include branch from f742645 to 0af3e0c Compare July 5, 2022 16:59
@sapphi-red sapphi-red marked this pull request as ready for review July 5, 2022 16:59
@patak-dev patak-dev merged commit 6e0dd3a into vitejs:main Jul 6, 2022
@sapphi-red sapphi-red deleted the fix/css-module-include branch July 7, 2022 16:55
sapphi-red added a commit to sapphi-red/vite that referenced this pull request Jul 7, 2022
@sapphi-red sapphi-red mentioned this pull request Jul 7, 2022
9 tasks
patak-dev pushed a commit that referenced this pull request Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release

Projects

None yet

2 participants