Skip to content

Commit

Permalink
Allows projects to opt out of the base Tailwind styles (#2959)
Browse files Browse the repository at this point in the history
* adding an option to opt-out of the Tailwind base styles

* chore: adding changeset description
  • Loading branch information
Tony Sullivan authored Apr 1, 2022
1 parent 2886cc2 commit 226822c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-zoos-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/tailwind': patch
---

Adds an option to opt-out of the default base styles for the Tailwind integration
13 changes: 13 additions & 0 deletions packages/integrations/tailwind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export default {
}
```

We will include `@tailwind` directives for each of Tailwind's layers to enable Tailwind styles by default. If you need to customize this behavior, with Tailwind's [`@layer` directive](https://tailwindcss.com/docs/functions-and-directives#layer) for example, opt-out via the `config.applyBaseStyles` integration option:

__astro.config.mjs__

```js
export default {
// ...
integrations: [tailwind({
config: { applyBaseStyles: false },
})],
}
```

You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.

[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
Expand Down
15 changes: 13 additions & 2 deletions packages/integrations/tailwind/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ type TailwindOptions =
* @default true
*/
applyAstroPreset?: boolean;
/**
* Apply Tailwind's base styles
* Disabling this is useful when further customization of Tailwind styles
* and directives is required. See {@link https://tailwindcss.com/docs/functions-and-directives#tailwind Tailwind's docs}
* for more details on directives and customization.
* @default: true
*/
applyBaseStyles?: boolean;
};
}
| undefined;

export default function tailwindIntegration(options: TailwindOptions): AstroIntegration {
const applyAstroConfigPreset = options?.config?.applyAstroPreset ?? true;
const applyBaseStyles = options?.config?.applyBaseStyles ?? true;
const customConfigPath = options?.config?.path;
return {
name: '@astrojs/tailwind',
Expand All @@ -71,8 +80,10 @@ export default function tailwindIntegration(options: TailwindOptions): AstroInte
config.styleOptions.postcss.plugins.push(tailwindPlugin(tailwindConfig));
config.styleOptions.postcss.plugins.push(autoprefixerPlugin);

// Inject the Tailwind base import
injectScript('page-ssr', `import '@astrojs/tailwind/base.css';`);
if (applyBaseStyles) {
// Inject the Tailwind base import
injectScript('page-ssr', `import '@astrojs/tailwind/base.css';`);
}
},
},
};
Expand Down

0 comments on commit 226822c

Please sign in to comment.