Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css)!: remove css default export #14125

Merged
merged 7 commits into from
Sep 15, 2023

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Aug 16, 2023

Description

Removes CSS default export and deprecation warnings.
Also removes the ?used hack.

refs #11094 #11121 #8278

fixes #12001 (indirectly)
fixes #13885 (indirectly)

Additional context

I recommend merging this PR without squashing as I believe it's better for debugging later.


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 PR Title 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 breaking change p3-significant High priority enhancement (priority) labels Aug 16, 2023
@stackblitz
Copy link

stackblitz bot commented Aug 16, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red force-pushed the feat/remove-css-default-export branch from f761c26 to ded43c9 Compare August 17, 2023 14:04
@sapphi-red sapphi-red added this to the 5.0 milestone Aug 17, 2023
@sapphi-red sapphi-red force-pushed the feat/remove-css-default-export branch from b4daf02 to 8698140 Compare August 20, 2023 09:14
@sapphi-red sapphi-red marked this pull request as ready for review August 20, 2023 09:17
@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci

This comment was marked as outdated.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

LGTM. Ok with non-squashing this one 👍

@sapphi-red
Copy link
Member Author

I'll run the ecosystem ci as the previous run was before the main branch was merged.

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Sep 13, 2023

📝 Ran ecosystem CI: Open

suite result
analogjs ✅ success
astro ✅ success
histoire ❌ failure
ladle ❌ failure
laravel ✅ success
marko ✅ success
nuxt ✅ success
nx ✅ success
previewjs ✅ success
qwik ❌ failure
rakkas ✅ success
sveltekit ✅ success
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ❌ failure
vite-plugin-react-swc ✅ success
vite-plugin-svelte ❌ failure
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success

@sapphi-red
Copy link
Member Author

qwik is the only failure that isn't failing in main branch.
The reason it is failing is that there were places in the documentation where it was using the css default export. It should be fixed by QwikDev/qwik#5161.

@sapphi-red sapphi-red merged commit efe003c into vitejs:main Sep 15, 2023
10 checks passed
@sapphi-red sapphi-red deleted the feat/remove-css-default-export branch September 16, 2023 05:20
@emosheeep
Copy link
Contributor

emosheeep commented Dec 1, 2023

Leave a way here to restore the legacy behavior of previous version, anyways, someone might need it.

// works for versions before vite5
import { type PluginOption, preprocessCSS, type ResolvedConfig } from 'vite';

export function createCssModulePlugin(): PluginOption {
  let resolvedConfig: ResolvedConfig;
  let moduleCache: Map<string, Record<string, string>>;

  return [
    {
      name: 'plugin:force-css-module',
      enforce: 'post',
      configResolved(config) {
        resolvedConfig = config;
      },
      buildStart() {
        // Ensure a new cache for every build (i.e. rebuilding in watch mode)
        moduleCache = new Map();
      },
      async transform(code, id) {
        if (/(?<!global|module)\.scss(?!\?inline)$/.test(id)) {
          const { modules, code: css } = await preprocessCSS(code, id + '.module.scss', resolvedConfig);
          moduleCache.set(id, modules);
          return css;
        }
      },
    },
    {
      name: 'plugin:force-css-module-post',
      enforce: 'post',
      async transform(_, id) {
        const moduleCode = moduleCache.get(id);
        if (moduleCode) {
          return {
            code: `export default JSON.parse(${JSON.stringify(moduleCode)})`,
            map: { mappings: '' },
            moduleSideEffects: 'no-treeshake',
          };
        }
      },
    },
  ];
}

@sapphi-red sapphi-red mentioned this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change p3-significant High priority enhancement (priority)
Projects
None yet
3 participants