1
- import { deleteFile , expectFileToMatch , writeFile } from '../../../utils/fs' ;
1
+ import { deleteFile , expectFileToMatch , replaceInFile , writeFile } from '../../../utils/fs' ;
2
2
import { installPackage , uninstallPackage } from '../../../utils/packages' ;
3
3
import { ng , silentExec } from '../../../utils/process' ;
4
+ import { updateJsonFile } from '../../../utils/project' ;
4
5
import { expectToFail } from '../../../utils/utils' ;
5
6
6
7
export default async function ( ) {
@@ -14,12 +15,18 @@ export default async function () {
14
15
15
16
// Create configuration file
16
17
await silentExec ( 'npx' , 'tailwindcss' , 'init' ) ;
18
+ await replaceInFile ( 'tailwind.config.js' , `purge: [],` , `purge: ['./src/**/*.{html,ts}'],` ) ;
19
+ await updateJsonFile ( 'angular.json' , json => {
20
+ json . projects [ 'test-project' ] . architect . build . configurations . production . budgets = [
21
+ { type : 'all' , maximumError : '100mb' } ,
22
+ ] ;
23
+ } ) ;
17
24
18
25
// Add Tailwind directives to a component style
19
- await writeFile ( 'src/app/app.component.css' , '@tailwind base; @tailwind components;' ) ;
26
+ await writeFile ( 'src/app/app.component.css' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ;
20
27
21
28
// Add Tailwind directives to a global style
22
- await writeFile ( 'src/styles.css' , '@tailwind base; @tailwind components;' ) ;
29
+ await writeFile ( 'src/styles.css' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ;
23
30
24
31
// Build should succeed and process Tailwind directives
25
32
await ng ( 'build' ) ;
@@ -28,19 +35,66 @@ export default async function () {
28
35
await expectFileToMatch ( 'dist/test-project/styles.css' , / : : p l a c e h o l d e r / ) ;
29
36
await expectFileToMatch ( 'dist/test-project/main.js' , / : : p l a c e h o l d e r / ) ;
30
37
await expectToFail ( ( ) =>
31
- expectFileToMatch ( 'dist/test-project/styles.css' , '@tailwind base; @tailwind components;' ) ,
38
+ expectFileToMatch ( 'dist/test-project/styles.css' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ,
32
39
) ;
33
40
await expectToFail ( ( ) =>
34
- expectFileToMatch ( 'dist/test-project/main.js' , '@tailwind base; @tailwind components;' ) ,
41
+ expectFileToMatch ( 'dist/test-project/main.js' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ,
35
42
) ;
36
43
44
+
45
+ await writeFile ( 'src/app/app.component.html' , '<div class="py-2 px-4 rounded-md bg-red-400">Test</div>' ) ;
46
+ await ng ( 'build' , '--prod' , '--output-hashing=none' ) ;
47
+ await expectFileToMatch ( 'dist/test-project/styles.css' , / \. r o u n d e d - m d / ) ;
48
+ await expectFileToMatch ( 'dist/test-project/main.js' , / \. r o u n d e d - m d / ) ;
49
+ await expectToFail ( ( ) =>
50
+ expectFileToMatch ( 'dist/test-project/styles.css' , / \. p y - 3 / ) ,
51
+ ) ;
52
+ await expectToFail ( ( ) =>
53
+ expectFileToMatch ( 'dist/test-project/main.js' , / \. p y - 3 / ) ,
54
+ ) ;
55
+ await replaceInFile ( 'tailwind.config.js' , `purge: ['./src/**/*.{html,ts}'],` , `purge: {
56
+ content: [
57
+ './src/**/*.{html,ts}',
58
+ ]
59
+ },` ) ;
60
+ await ng ( 'build' , '--prod' , '--output-hashing=none' ) ;
61
+ await expectFileToMatch ( 'dist/test-project/styles.css' , / \. r o u n d e d - m d / ) ;
62
+ await expectFileToMatch ( 'dist/test-project/main.js' , / \. r o u n d e d - m d / ) ;
63
+ await expectToFail ( ( ) =>
64
+ expectFileToMatch ( 'dist/test-project/styles.css' , / \. p y - 3 / ) ,
65
+ ) ;
66
+ await expectToFail ( ( ) =>
67
+ expectFileToMatch ( 'dist/test-project/main.js' , / \. p y - 3 / ) ,
68
+ ) ;
69
+
70
+ await replaceInFile ( 'tailwind.config.js' , `purge: {` , `purge: { enabled: false,` ) ;
71
+ await ng ( 'build' , '--prod' , '--output-hashing=none' ) ;
72
+ expectFileToMatch ( 'dist/test-project/styles.css' , / \. p y - 3 / ) ,
73
+ expectFileToMatch ( 'dist/test-project/main.js' , / \. p y - 3 / ) ,
74
+ await replaceInFile ( 'tailwind.config.js' , `purge: { enabled: false,` , `purge: { enabled: true,` ) ;
75
+ await ng ( 'build' ) ;
76
+ await expectToFail ( ( ) =>
77
+ expectFileToMatch ( 'dist/test-project/styles.css' , / \. p y - 3 / ) ,
78
+ ) ;
79
+ await expectToFail ( ( ) =>
80
+ expectFileToMatch ( 'dist/test-project/main.js' , / \. p y - 3 / ) ,
81
+ ) ;
82
+
83
+
84
+ await writeFile ( 'tailwind.config.js' , 'module.exports = () => {}' ) ;
85
+ const { stderr : _err } = await ng ( 'build' ) ;
86
+ if ( ! _err . includes ( "file export function instead of object" ) ) {
87
+ throw new Error ( 'Expected tailwind config error' ) ;
88
+ }
89
+
90
+
37
91
// Remove configuration file
38
92
await deleteFile ( 'tailwind.config.js' ) ;
39
93
40
94
// Ensure Tailwind is disabled when no configuration file is present
41
95
await ng ( 'build' ) ;
42
- await expectFileToMatch ( 'dist/test-project/styles.css' , '@tailwind base; @tailwind components;' ) ;
43
- await expectFileToMatch ( 'dist/test-project/main.js' , '@tailwind base; @tailwind components;' ) ;
96
+ await expectFileToMatch ( 'dist/test-project/styles.css' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ;
97
+ await expectFileToMatch ( 'dist/test-project/main.js' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ;
44
98
45
99
// Recreate configuration file
46
100
await silentExec ( 'npx' , 'tailwindcss' , 'init' ) ;
@@ -55,6 +109,6 @@ export default async function () {
55
109
}
56
110
57
111
// Tailwind directives should be unprocessed with missing package
58
- await expectFileToMatch ( 'dist/test-project/styles.css' , '@tailwind base; @tailwind components;' ) ;
59
- await expectFileToMatch ( 'dist/test-project/main.js' , '@tailwind base; @tailwind components;' ) ;
112
+ await expectFileToMatch ( 'dist/test-project/styles.css' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ;
113
+ await expectFileToMatch ( 'dist/test-project/main.js' , '@tailwind base; @tailwind components; @tailwind utilities ' ) ;
60
114
}
0 commit comments