From 3ada25d7d9ebbdff469d31399ac112d3d7fb7249 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Wed, 16 Jun 2021 18:36:19 +0100 Subject: [PATCH] Pass configured Tailwind config file to the `tailwindcss` plugin (#352) * fix tailwind config filename * pass configured config file to tailwindcss * add changeset * remove `tailwindConfig` from `CompileOptions` interface --- .changeset/breezy-parrots-bathe.md | 5 +++++ docs/styling.md | 2 +- packages/astro/src/@types/compiler.ts | 1 - packages/astro/src/compiler/transform/styles.ts | 4 ++-- packages/astro/src/runtime.ts | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/breezy-parrots-bathe.md diff --git a/.changeset/breezy-parrots-bathe.md b/.changeset/breezy-parrots-bathe.md new file mode 100644 index 000000000..99b250914 --- /dev/null +++ b/.changeset/breezy-parrots-bathe.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Pass configured Tailwind config file to the tailwindcss plugin diff --git a/docs/styling.md b/docs/styling.md index 2f57cd21f..86ce2e840 100644 --- a/docs/styling.md +++ b/docs/styling.md @@ -107,7 +107,7 @@ Be sure to add the config path to `astro.config.mjs`, so that Astro enables JIT // astro.config.mjs export default { + devOptions: { -+ tailwindConfig: './tailwindConfig.js', ++ tailwindConfig: './tailwind.config.js', + }, }; ``` diff --git a/packages/astro/src/@types/compiler.ts b/packages/astro/src/@types/compiler.ts index 6435aea80..d35dcfd09 100644 --- a/packages/astro/src/@types/compiler.ts +++ b/packages/astro/src/@types/compiler.ts @@ -7,5 +7,4 @@ export interface CompileOptions { astroConfig: AstroConfig; hmrPort?: number; mode: RuntimeMode; - tailwindConfig?: string; } diff --git a/packages/astro/src/compiler/transform/styles.ts b/packages/astro/src/compiler/transform/styles.ts index e1199e9a6..d5a10b323 100644 --- a/packages/astro/src/compiler/transform/styles.ts +++ b/packages/astro/src/compiler/transform/styles.ts @@ -124,7 +124,7 @@ async function transformStyle(code: string, { logging, type, filename, scopedCla try { const require = createRequire(import.meta.url); const tw = require.resolve('tailwindcss', { paths: [import.meta.url, process.cwd()] }); - postcssPlugins.push(require(tw) as any); + postcssPlugins.push(require(tw)(tailwindConfig) as any); } catch (err) { error(logging, 'transform', err); throw new Error(`tailwindcss not installed. Try running \`npm install tailwindcss\` and trying again.`); @@ -214,7 +214,7 @@ export default function transformStyles({ compileOptions, filename, fileID }: Tr type: (langAttr && langAttr.value[0] && langAttr.value[0].data) || undefined, filename, scopedClass, - tailwindConfig: compileOptions.tailwindConfig, + tailwindConfig: compileOptions.astroConfig.devOptions.tailwindConfig, }) ); return; diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index e7f9efd1c..124c2ffdc 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -399,7 +399,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO config: { plugins: { [resolveDependency('autoprefixer')]: {}, - ...(astroConfig.devOptions.tailwindConfig ? { [resolveDependency('tailwindcss')]: {} } : {}), + ...(astroConfig.devOptions.tailwindConfig ? { [resolveDependency('tailwindcss')]: astroConfig.devOptions.tailwindConfig } : {}), }, }, },