1
- import { defineAddon } from '@sveltejs/cli-core' ;
2
- import { addImports } from '@sveltejs/cli-core/css' ;
1
+ import { defineAddon , defineAddonOptions } from '@sveltejs/cli-core' ;
2
+ import { addAtRule , addImports } from '@sveltejs/cli-core/css' ;
3
3
import { array , functions , imports , object , exports } from '@sveltejs/cli-core/js' ;
4
4
import { parseCss , parseJson , parseScript , parseSvelte } from '@sveltejs/cli-core/parsers' ;
5
5
import { addSlot } from '@sveltejs/cli-core/html' ;
6
6
7
+ type Plugin = {
8
+ id : string ;
9
+ package : string ;
10
+ version : string ;
11
+ identifier : string ;
12
+ } ;
13
+
14
+ const plugins : Plugin [ ] = [
15
+ {
16
+ id : 'typography' ,
17
+ package : '@tailwindcss/typography' ,
18
+ version : '^0.5.15' ,
19
+ identifier : 'typography'
20
+ } ,
21
+ {
22
+ id : 'forms' ,
23
+ package : '@tailwindcss/forms' ,
24
+ version : '^0.5.9' ,
25
+ identifier : 'forms'
26
+ }
27
+ ] ;
28
+
29
+ const options = defineAddonOptions ( {
30
+ plugins : {
31
+ type : 'multiselect' ,
32
+ question : 'Which plugins would you like to add?' ,
33
+ options : plugins . map ( ( p ) => ( { value : p . id , label : p . id , hint : p . package } ) ) ,
34
+ default : [ ]
35
+ }
36
+ } ) ;
37
+
7
38
export default defineAddon ( {
8
39
id : 'tailwindcss' ,
9
40
alias : 'tailwind' ,
10
41
shortDescription : 'css framework' ,
11
42
homepage : 'https://tailwindcss.com' ,
12
- options : { } ,
13
- run : ( { sv, typescript, kit, dependencyVersion } ) => {
43
+ options,
44
+ run : ( { sv, options , typescript, kit, dependencyVersion } ) => {
14
45
const ext = typescript ? 'ts' : 'js' ;
15
46
const prettierInstalled = Boolean ( dependencyVersion ( 'prettier' ) ) ;
16
47
@@ -19,6 +50,12 @@ export default defineAddon({
19
50
20
51
if ( prettierInstalled ) sv . devDependency ( 'prettier-plugin-tailwindcss' , '^0.6.11' ) ;
21
52
53
+ for ( const plugin of plugins ) {
54
+ if ( ! options . plugins . includes ( plugin . id ) ) continue ;
55
+
56
+ sv . devDependency ( plugin . package , plugin . version ) ;
57
+ }
58
+
22
59
// add the vite plugin
23
60
sv . file ( `vite.config.${ ext } ` , ( content ) => {
24
61
const { ast, generateCode } = parseScript ( content ) ;
@@ -46,6 +83,12 @@ export default defineAddon({
46
83
47
84
const nodes = addImports ( ast , [ "'tailwindcss'" ] ) ;
48
85
86
+ for ( const plugin of plugins ) {
87
+ if ( ! options . plugins . includes ( plugin . id ) ) continue ;
88
+
89
+ addAtRule ( ast , 'plugin' , `'${ plugin . package } '` , true ) ;
90
+ }
91
+
49
92
if (
50
93
originalFirst !== ast . first &&
51
94
originalFirst ?. type === 'atrule' &&
0 commit comments