Skip to content

Commit

Permalink
Compile StyleX before Vite CSS plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
HorusGoul committed Mar 29, 2024
1 parent b630c7a commit 5bf5f79
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/vite-plugin-stylex/src/experimental.mts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ export default function styleXVitePlugin({

return [
{
name: "vite-plugin-stylex",
name: "vite-plugin-stylex:pre",
enforce: "pre",

configResolved(config) {
isProd = config.command === "build";
Expand Down Expand Up @@ -278,11 +279,6 @@ export default function styleXVitePlugin({
server = _server;
},

shouldTransformCachedModule({ id, meta }) {
stylexRules[id] = meta.stylex;
return false;
},

async transform(inputCode, id, { ssr: isSSR = false } = {}) {
if (/\.css/.test(id) && inputCode.includes(STYLEX_REPLACE_RULE)) {
modulesToInvalidate.set(id, inputCode);
Expand All @@ -295,7 +291,17 @@ export default function styleXVitePlugin({
return inputCode.replace(STYLEX_REPLACE_RULE, compileStyleX());
}
}
},
},
{
name: "vite-plugin-stylex",

shouldTransformCachedModule({ id, meta }) {
stylexRules[id] = meta.stylex;
return false;
},

async transform(inputCode, id) {
if (
!Array.from(styleXRelatedModules).some(
(importName) =>
Expand Down

0 comments on commit 5bf5f79

Please sign in to comment.