Skip to content

Commit 0323a35

Browse files
committed
fix(@angular-devkit/build-angular): add tailwindcss support for version 3
1 parent f9187bc commit 0323a35

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

packages/angular_devkit/build_angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"karma": "^6.3.0",
8282
"ng-packagr": "^13.0.0 || ^13.1.0-next",
8383
"protractor": "^7.0.0",
84-
"tailwindcss": "^2.0.0",
84+
"tailwindcss": "^2.0.0 || ^3.0.0",
8585
"typescript": ">=4.4.3 <4.6"
8686
},
8787
"peerDependenciesMeta": {

tests/legacy-cli/e2e/tests/build/styles/tailwind.ts tests/legacy-cli/e2e/tests/build/styles/tailwind-v2.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import { ng, silentExec } from '../../../utils/process';
44
import { expectToFail } from '../../../utils/utils';
55

66
export default async function () {
7-
// Tailwind is not supported in Node.js 10
8-
if (process.version.startsWith('v10')) {
9-
return;
10-
}
11-
127
// Install Tailwind
13-
await installPackage('tailwindcss');
8+
await installPackage('tailwindcss@2');
149

1510
// Create configuration file
1611
await silentExec('npx', 'tailwindcss', 'init');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { deleteFile, expectFileToMatch, writeFile } from '../../../utils/fs';
2+
import { installPackage, uninstallPackage } from '../../../utils/packages';
3+
import { ng, silentExec } from '../../../utils/process';
4+
import { expectToFail } from '../../../utils/utils';
5+
6+
export default async function () {
7+
// Install Tailwind
8+
await installPackage('tailwindcss@3');
9+
10+
// Create configuration file
11+
await silentExec('npx', 'tailwindcss', 'init');
12+
13+
// Add Tailwind directives to a component style
14+
await writeFile('src/app/app.component.css', '@tailwind base; @tailwind components;');
15+
16+
// Add Tailwind directives to a global style
17+
await writeFile('src/styles.css', '@tailwind base; @tailwind components;');
18+
19+
// Build should succeed and process Tailwind directives
20+
await ng('build', '--configuration=development');
21+
22+
// Check for Tailwind output
23+
await expectFileToMatch('dist/test-project/styles.css', /::placeholder/);
24+
await expectFileToMatch('dist/test-project/main.js', /::placeholder/);
25+
await expectToFail(() =>
26+
expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;'),
27+
);
28+
await expectToFail(() =>
29+
expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;'),
30+
);
31+
32+
// Remove configuration file
33+
await deleteFile('tailwind.config.js');
34+
35+
// Ensure Tailwind is disabled when no configuration file is present
36+
await ng('build', '--configuration=development');
37+
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
38+
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
39+
40+
// Recreate configuration file
41+
await silentExec('npx', 'tailwindcss', 'init');
42+
43+
// Uninstall Tailwind
44+
await uninstallPackage('tailwindcss');
45+
46+
// Ensure installation warning is present
47+
const { stderr } = await ng('build', '--configuration=development');
48+
if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) {
49+
throw new Error('Expected tailwind installation warning');
50+
}
51+
52+
// Tailwind directives should be unprocessed with missing package
53+
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
54+
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
55+
}

0 commit comments

Comments
 (0)