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: panda css use vite-macro plugin #4588

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions packages/qwik/src/cli/code-mod/code-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function updateViteConfig(ts: TypeScript, sourceText: string, updates?: V
!updates?.imports &&
!updates?.qwikViteConfig &&
!updates?.viteConfig &&
!updates?.vitePlugins
!updates?.vitePlugins &&
!updates?.vitePluginsPrepend
) {
return null;
}
Expand All @@ -37,7 +38,10 @@ export function updateViteConfig(ts: TypeScript, sourceText: string, updates?: V
if (
ts.isIdentifier(s.expression.expression) &&
s.expression.expression.text === 'defineConfig' &&
(updates.viteConfig || updates.qwikViteConfig || updates.vitePlugins)
(updates.viteConfig ||
updates.qwikViteConfig ||
updates.vitePlugins ||
updates.vitePluginsPrepend)
) {
statements.push(
ts.factory.updateExportAssignment(
Expand Down Expand Up @@ -346,7 +350,7 @@ function updateVitConfigObj(
if (updates.viteConfig) {
obj = updateObjectLiteralExpression(ts, obj, updates.viteConfig);
}
if (updates.vitePlugins || updates.qwikViteConfig) {
if (updates.vitePlugins || updates.vitePluginsPrepend || updates.qwikViteConfig) {
obj = updatePlugins(ts, obj, updates);
}
return obj;
Expand Down Expand Up @@ -399,6 +403,22 @@ function updatePluginsArray(
}
}

if (updates.vitePluginsPrepend) {
for (const vitePlugin of updates.vitePluginsPrepend) {
const pluginExp = createPluginCall(ts, vitePlugin);
const pluginName = (pluginExp?.expression as Identifier | null)?.escapedText;
const alreadyDefined = elms.some(
(el) =>
ts.isCallExpression(el) &&
ts.isIdentifier(el.expression) &&
el.expression.escapedText === pluginName
);
if (pluginExp && !alreadyDefined) {
elms.unshift(pluginExp);
}
}
}

if (updates.qwikViteConfig) {
for (let i = 0; i < elms.length; i++) {
const elm = elms[i];
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface ViteConfigUpdates {
imports?: EnsureImport[];
viteConfig?: { [key: string]: string };
vitePlugins?: string[];
vitePluginsPrepend?: string[];
qwikViteConfig?: { [key: string]: string };
}

Expand Down
17 changes: 15 additions & 2 deletions starters/features/pandacss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
"pandacss.generate": "panda codegen"
},
"devDependencies": {
"@builder.io/vite-plugin-macro": "~0.0.6",
"@pandacss/dev": "^0.3.2"
},
"__qwik__": {
"displayName": "Integration: PandaCSS (styling)",
"priority": -10,
"postInstall": "panda codegen",
"viteConfig": {},
"docs": [
"https://panda-css.com/docs/getting-started/qwik"
]
],
"viteConfig": {
"imports": [
{
"namedImports": [
"macroPlugin"
],
"importPath": "@builder.io/vite-plugin-macro"
}
],
"vitePluginsPrepend": [
"macroPlugin({ preset: 'pandacss' })"
]
}
}
}