Skip to content

Commit 2bc2395

Browse files
fix(nx-plugin): generate postcss configuration for Tailwind (#1951)
1 parent fd92b32 commit 2bc2395

File tree

7 files changed

+41
-22
lines changed

7 files changed

+41
-22
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": {
3+
"@tailwindcss/postcss": {}
4+
}
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Config } from 'tailwindcss';
2+
import { createGlobPatternsForDependencies } from '@nx/angular/tailwind';
3+
import { join } from 'node:path';
4+
5+
export default {
6+
content: [
7+
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html,md,analog,ag}'),
8+
...createGlobPatternsForDependencies(__dirname),
9+
],
10+
theme: {
11+
extend: {},
12+
},
13+
plugins: [],
14+
} satisfies Config;

packages/nx-plugin/src/generators/app/files/template-angular/vite.config.ts__template__

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import analog from '@analogjs/platform';
44
import { defineConfig } from 'vite';
55
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
6-
<% if (addTailwind) { %>
7-
// @ts-expect-error @tailwindcss/vite currently uses mts. TypeScript is complaining this, but it works as expected.
8-
import tailwindcss from '@tailwindcss/vite';
9-
<% } %>
106

117
// https://vitejs.dev/config/
128
export default defineConfig(({ mode }) => {
@@ -24,9 +20,6 @@ export default defineConfig(({ mode }) => {
2420
},
2521
},
2622
plugins: [
27-
<% if (addTailwind) { %>
28-
tailwindcss(),
29-
<% } %>
3023
analog(),
3124
nxViteTsPaths(),
3225
],

packages/nx-plugin/src/generators/app/generator.spec.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,17 @@ describe('nx-plugin generator', () => {
116116
expect(hasTailwindConfigFile).toBeTruthy();
117117
expect(hasPostCSSConfigFile).toBeTruthy();
118118
} else {
119-
expect(dependencies['@tailwindcss/vite']).toBeDefined();
119+
expect(dependencies['@tailwindcss/postcss']).toBeDefined();
120120

121+
const hasPostCSSConfigFile = tree.exists(
122+
'apps/tailwind-app/.postcssrc.json',
123+
);
121124
const hasCorrectCssImplementation = tree
122125
.read('apps/tailwind-app/src/styles.css')
123126
.includes(`@import 'tailwindcss';`);
124127

125-
const regex = /plugins: \[.*\btailwindcss\(\)/s;
126-
127-
const viteConfig = tree
128-
.read('apps/tailwind-app/vite.config.ts')
129-
.toString();
130-
131-
expect(regex.test(viteConfig)).toBeTruthy();
132128
expect(hasCorrectCssImplementation).toBeTruthy();
129+
expect(hasPostCSSConfigFile).toBeTruthy();
133130
}
134131
};
135132

packages/nx-plugin/src/generators/app/lib/add-tailwind-helpers.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function addTailwindRequiredPackages(tree: Tree): GeneratorCallback {
5757
{
5858
postcss: pkgVersions.postcss,
5959
tailwindcss: pkgVersions.tailwindcss,
60-
'@tailwindcss/vite': pkgVersions['@tailwindcss/vite'],
60+
'@tailwindcss/postcss': pkgVersions['@tailwindcss/postcss'],
6161
},
6262
{},
6363
);
@@ -245,4 +245,17 @@ export function addTailwindConfigFile(
245245
);
246246
return;
247247
}
248+
249+
if (tailwindInstalledVersion === '4') {
250+
generateFiles(
251+
tree,
252+
joinPathFragments(__dirname, '..', 'files', 'tailwind/v4'),
253+
project.root,
254+
{
255+
relativeSourceRoot: relative(project.root, project.sourceRoot),
256+
template: '',
257+
},
258+
);
259+
return;
260+
}
248261
}

packages/nx-plugin/src/generators/app/versions/tailwind-dependencies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
const tailwindDependencyKeys = [
88
'postcss',
99
'tailwindcss',
10-
'@tailwindcss/vite',
10+
'@tailwindcss/postcss',
1111
] as const;
1212

1313
export type TailwindDependency = (typeof tailwindDependencyKeys)[number];
@@ -19,6 +19,6 @@ export const getTailwindDependencies = (): Record<
1919
return {
2020
postcss: V18_X_POSTCSS,
2121
tailwindcss: V18_X_TAILWINDCSS,
22-
'@tailwindcss/vite': V18_X_TAILWINDCSS_VITE,
22+
'@tailwindcss/postcss': V18_X_TAILWINDCSS_VITE,
2323
};
2424
};

packages/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ import analog from '@analogjs/platform';
117117
import { defineConfig } from 'vite';
118118
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
119119
120-
// @ts-expect-error @tailwindcss/vite currently uses mts. TypeScript is complaining this, but it works as expected.
121-
import tailwindcss from '@tailwindcss/vite';
122-
123120
// https://vitejs.dev/config/
124121
export default defineConfig(({ mode }) => {
125122
return {
@@ -135,7 +132,7 @@ export default defineConfig(({ mode }) => {
135132
allow: ['.'],
136133
},
137134
},
138-
plugins: [tailwindcss(), analog(), nxViteTsPaths()],
135+
plugins: [analog(), nxViteTsPaths()],
139136
test: {
140137
globals: true,
141138
environment: 'jsdom',

0 commit comments

Comments
 (0)