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

in build time, generateCSS runs before transformCSS, causing @layer missing in the output #261

Open
upupming opened this issue Dec 6, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@upupming
Copy link

upupming commented Dec 6, 2021

Describe the bug

Input App.vue:

<style>
.test-1 {
  @apply bg-light-700;
}

@layer base {
  .test-2 {
    color: red;
  }
}
</style>

Output:

.test-1 {
  --tw-bg-opacity: 1;
  background-color: rgba(233, 236, 239, var(--tw-bg-opacity));
}

You can see the .test-2 is missing in the built output, this is caused by the load hook (ctx.utils.generateCSS('base')) is ran before transform (transformCSS(code, id)). So although transformCSS added the test-2 to base layer, the generating produre has run before and wont generate again, so we got no test-2 in the output.

Minimal Reproductions

https://github.com/upupming/windicss-missig-layer-build-time#bug-2----build-time-layer-missing

Versions

  • vite-plugin-windicss: 1.5.4
  • vite: 2.6.14
  • framework(vue/react/svelte/etc): vue

Additonal Context

I believe the root cause is that we can send the updated layer to the browser by ViteDevServer & send HMR in dev mode like this:

onLayerUpdated() {
if (server)
reloadCssModules(server)
},

export function reloadChangedCssModules(server: ViteDevServer, utils: WindiPluginUtils) {
const cssModules = getCssModules(server, getChangedModuleNames(utils))
invalidateCssModules(server, cssModules)
sendHmrReload(server, cssModules)
return cssModules
}

But in build time, we cannot rely on this feature anymore, what do you think?

@upupming upupming added the bug Something isn't working label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant