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
This commit is contained in:
Brad Cornes 2021-06-16 18:36:19 +01:00 committed by GitHub
parent c0804fc8cd
commit 3ada25d7d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Pass configured Tailwind config file to the tailwindcss plugin

View file

@ -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',
+ },
};
```

View file

@ -7,5 +7,4 @@ export interface CompileOptions {
astroConfig: AstroConfig;
hmrPort?: number;
mode: RuntimeMode;
tailwindConfig?: string;
}

View file

@ -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;

View file

@ -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 } : {}),
},
},
},