@@ -5,20 +5,42 @@ import autoprefixer from 'autoprefixer';
55import postcss from 'postcss' ;
66import sass from 'sass' ;
77
8+ /**
9+ * @typedef {import('tailwindcss/tailwind-config').TailwindConfig } TailwindConfig
10+ */
11+ const defaultTailwindConfig = /** @type {TailwindConfig } */ ( {
12+ darkMode : false ,
13+ theme : { } ,
14+ } ) ;
15+
816/**
917 * Build CSS bundles from SASS or CSS inputs.
1018 *
1119 * @param {string[] } inputs - An array of CSS or SCSS file paths specifying the
1220 * entry points of style bundles. The output files will be written to
1321 * `build/styles/[name].css` where `[name]` is the basename of the input file
1422 * minus the file extension.
23+ * @param {object } [options]
24+ * @param {TailwindConfig } [options.tailwindConfig]
25+ * Optional tailwind config object
1526 * @return {Promise<void> } Promise for completion of the build.
1627 */
17- export async function buildCSS ( inputs ) {
28+ export async function buildCSS (
29+ inputs ,
30+ { tailwindConfig = defaultTailwindConfig } = { }
31+ ) {
1832 const outDir = 'build/styles' ;
1933 const minify = process . env . NODE_ENV === 'production' ;
2034 await mkdir ( outDir , { recursive : true } ) ;
2135
36+ /** @type {typeof import('tailwindcss') } */
37+ let tailwindcss ;
38+ try {
39+ tailwindcss = ( await import ( 'tailwindcss' ) ) . default ;
40+ } catch {
41+ // Ignored
42+ }
43+
2244 await Promise . all (
2345 inputs . map ( async input => {
2446 const output = `${ outDir } /${ basename ( input , extname ( input ) ) } .css` ;
@@ -31,9 +53,15 @@ export async function buildCSS(inputs) {
3153 sourceMap : sourcemapPath ,
3254 } ) ;
3355
34- const cssProcessor = postcss ( [ autoprefixer ( ) ] ) ;
56+ const optionalPlugins = [ ] ;
57+ if ( tailwindcss ) {
58+ optionalPlugins . push ( tailwindcss ( tailwindConfig ) ) ;
59+ }
60+
61+ const cssProcessor = postcss ( [ ...optionalPlugins , autoprefixer ( ) ] ) ;
62+
3563 const postcssResult = await cssProcessor . process ( sassResult . css , {
36- from : output ,
64+ from : input ,
3765 to : output ,
3866 map : {
3967 inline : false ,
0 commit comments