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' ;
33import { array , functions , imports , object , exports } from '@sveltejs/cli-core/js' ;
44import { parseCss , parseJson , parseScript , parseSvelte } from '@sveltejs/cli-core/parsers' ;
55import { addSlot } from '@sveltejs/cli-core/html' ;
66
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+
738export default defineAddon ( {
839 id : 'tailwindcss' ,
940 alias : 'tailwind' ,
1041 shortDescription : 'css framework' ,
1142 homepage : 'https://tailwindcss.com' ,
12- options : { } ,
13- run : ( { sv, typescript, kit, dependencyVersion } ) => {
43+ options,
44+ run : ( { sv, options , typescript, kit, dependencyVersion } ) => {
1445 const ext = typescript ? 'ts' : 'js' ;
1546 const prettierInstalled = Boolean ( dependencyVersion ( 'prettier' ) ) ;
1647
@@ -19,6 +50,12 @@ export default defineAddon({
1950
2051 if ( prettierInstalled ) sv . devDependency ( 'prettier-plugin-tailwindcss' , '^0.6.11' ) ;
2152
53+ for ( const plugin of plugins ) {
54+ if ( ! options . plugins . includes ( plugin . id ) ) continue ;
55+
56+ sv . devDependency ( plugin . package , plugin . version ) ;
57+ }
58+
2259 // add the vite plugin
2360 sv . file ( `vite.config.${ ext } ` , ( content ) => {
2461 const { ast, generateCode } = parseScript ( content ) ;
@@ -46,6 +83,12 @@ export default defineAddon({
4683
4784 const nodes = addImports ( ast , [ "'tailwindcss'" ] ) ;
4885
86+ for ( const plugin of plugins ) {
87+ if ( ! options . plugins . includes ( plugin . id ) ) continue ;
88+
89+ addAtRule ( ast , 'plugin' , `'${ plugin . package } '` , true ) ;
90+ }
91+
4992 if (
5093 originalFirst !== ast . first &&
5194 originalFirst ?. type === 'atrule' &&
0 commit comments