0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

Rename tailwind integration options (#7391)

This commit is contained in:
Bjorn Lu 2023-06-15 23:40:42 +08:00 committed by GitHub
parent e407073c9e
commit 556fd694a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 48 deletions

View file

@ -0,0 +1,24 @@
---
'@astrojs/tailwind': major
---
Rename options `config.path` to `configFile`, and `config.applyBaseStyles` to `applyBaseStyles`. If you are using these options, you need to migrate to the new names.
```diff
// astro.config.mjs
import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
export default defineConfig({
integrations: [
tailwind({
- config: {
- path: '...',
- applyBaseStyles: true,
- },
+ configFile: '...',
+ applyBaseStyles: true,
}),
],
});
```

View file

@ -2,9 +2,12 @@
'@astrojs/tailwind': major '@astrojs/tailwind': major
--- ---
Let tailwind postcss plugin load its config file itself. This changes the `tailwind.config.js` loading behaviour where Tailwind would load the config file from `process.cwd()` instead of the project `root`. You can configure the integration's `config.path` option to load from a specific path instead. Let the `tailwindcss` PostCSS plugin load its config file itself. This changes the Tailwind config loading behaviour where it is loaded from `process.cwd()` instead of the project `root`.
If your Tailwind config file is not located in the current working directory, you will need to configure the integration's `configFile` option to load from a specific path:
```js ```js
// astro.config.mjs
import { defineConfig } from 'astro/config'; import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind'; import tailwind from '@astrojs/tailwind';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
@ -12,17 +15,16 @@ import { fileURLToPath } from 'url';
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
tailwind({ tailwind({
config: { configFile: fileURLToPath(new URL('./tailwind.config.cjs', import.meta.url)),
path: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
},
}), }),
], ],
}); });
``` ```
This change also requires a Tailwind config file to exist in your project as Astro's fallback value is no longer provided. It is set up automatically during `astro add tailwind`, but you can also manually create a `tailwind.config.cjs` file in your project root: This change also requires a Tailwind config file to exist in your project as a fallback config is no longer provided. It is set up automatically during `astro add tailwind`, but if it does not exist, you can manually create a `tailwind.config.cjs` file in your project root:
```js ```js
// tailwind.config.cjs
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
module.exports = { module.exports = {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],

View file

@ -6,9 +6,7 @@ import { fileURLToPath } from 'url';
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
tailwind({ tailwind({
config: { configFile: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
path: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
},
}), }),
], ],
vite: { vite: {

View file

@ -5,9 +5,7 @@ import { fileURLToPath } from 'url';
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
tailwind({ tailwind({
config: { configFile: fileURLToPath(new URL('./tailwind.config.cjs', import.meta.url)),
path: fileURLToPath(new URL('./tailwind.config.cjs', import.meta.url)),
},
}), }),
], ],
}); });

View file

@ -6,9 +6,7 @@ import { fileURLToPath } from 'url';
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
tailwind({ tailwind({
config: { configFile: fileURLToPath(new URL('./tailwind.config.cjs', import.meta.url)),
path: fileURLToPath(new URL('./tailwind.config.cjs', import.meta.url)),
},
}), }),
], ],
}); });

View file

@ -6,9 +6,7 @@ import { fileURLToPath } from 'url';
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
tailwind({ tailwind({
config: { configFile: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
path: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
},
}), }),
], ],
}); });

View file

@ -7,9 +7,7 @@ import { fileURLToPath } from 'url';
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
tailwind({ tailwind({
config: { configFile: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
path: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)),
},
}), }),
mdx(), mdx(),
], ],

View file

@ -84,9 +84,11 @@ If it isn't there, you add your own `tailwind.config.(js|cjs|mjs)` file to the r
The Astro Tailwind integration handles the communication between Astro and Tailwind and it has its own options. Change these in the `astro.config.mjs` file (_not_ the Tailwind configuration file) which is where your project's integration settings live. The Astro Tailwind integration handles the communication between Astro and Tailwind and it has its own options. Change these in the `astro.config.mjs` file (_not_ the Tailwind configuration file) which is where your project's integration settings live.
#### config.path #### configFile
Previously known as `config.path` in `@astrojs/tailwind` v3. See the [v4 changelog](https://github.com/withastro/astro/blob/main/packages/integrations/tailwind/CHANGELOG.md#400) for updating your config.
If you want to use a different Tailwind configuration file instead of the default `tailwind.config.(js|cjs|mjs)`, specify that file's location using this integration's `config.path` option. If `config.path` is relative, it will be resolved relative to the root. If you want to use a different Tailwind configuration file instead of the default `tailwind.config.(js|cjs|mjs)`, specify that file's location using this integration's `configFile` option. If `configFile` is relative, it will be resolved relative to the current working directory.
> **Warning** > **Warning**
> Changing this isn't recommended since it can cause problems with other tools that integrate with Tailwind, like the official Tailwind VSCode extension. > Changing this isn't recommended since it can cause problems with other tools that integrate with Tailwind, like the official Tailwind VSCode extension.
@ -100,14 +102,16 @@ import tailwind from '@astrojs/tailwind';
export default defineConfig({ export default defineConfig({
integrations: [tailwind({ integrations: [tailwind({
// Example: Provide a custom path to a Tailwind config file // Example: Provide a custom path to a Tailwind config file
config: { path: './custom-config.cjs' }, configFile: './custom-config.cjs',
})], })],
}); });
``` ```
#### config.applyBaseStyles #### applyBaseStyles
By default, the integration imports a basic `base.css` file on every page of your project. This basic CSS file includes the three main `@tailwind` directives: Previously known as `config.applyBaseStyles` in `@astrojs/tailwind` v3. See the [v4 changelog](https://github.com/withastro/astro/blob/main/packages/integrations/tailwind/CHANGELOG.md#400) for updating your config.
By default, the integration imports a basic `base.css` file on every page of your project. This basic CSS file includes the three main `@tailwind` directives:
```css ```css
/* The integration's default injected base.css file */ /* The integration's default injected base.css file */
@ -116,7 +120,7 @@ export default defineConfig({
@tailwind utilities; @tailwind utilities;
``` ```
To disable this default behavior, set `config.applyBaseStyles` to `false`. This can be useful if you need to define your own `base.css` file (to include a [`@layer` directive](https://tailwindcss.com/docs/functions-and-directives#layer), for example). This can also be useful if you do not want `base.css` to be imported on every page of your project. To disable this default behavior, set `applyBaseStyles` to `false`. This can be useful if you need to define your own `base.css` file (to include a [`@layer` directive](https://tailwindcss.com/docs/functions-and-directives#layer), for example). This can also be useful if you do not want `base.css` to be imported on every page of your project.
__`astro.config.mjs`__ __`astro.config.mjs`__
@ -127,7 +131,7 @@ export default defineConfig({
integrations: [tailwind({ integrations: [tailwind({
// Example: Disable injecting a basic `base.css` import on every page. // Example: Disable injecting a basic `base.css` import on every page.
// Useful if you need to define and/or import your own custom `base.css`. // Useful if you need to define and/or import your own custom `base.css`.
config: { applyBaseStyles: false }, applyBaseStyles: false,
})], })],
}); });
``` ```

View file

@ -46,29 +46,25 @@ async function getViteConfiguration(
}; };
} }
type TailwindOptions = type TailwindOptions = {
| { /**
config?: { * Path to your tailwind config file
/** * @default 'tailwind.config.js'
* Path to your tailwind config file */
* @default 'tailwind.config.js' configFile?: string;
*/ /**
path?: string; * Apply Tailwind's base styles
/** * Disabling this is useful when further customization of Tailwind styles
* Apply Tailwind's base styles * and directives is required. See {@link https://tailwindcss.com/docs/functions-and-directives#tailwind Tailwind's docs}
* Disabling this is useful when further customization of Tailwind styles * for more details on directives and customization.
* and directives is required. See {@link https://tailwindcss.com/docs/functions-and-directives#tailwind Tailwind's docs} * @default true
* for more details on directives and customization. */
* @default true applyBaseStyles?: boolean;
*/ };
applyBaseStyles?: boolean;
};
}
| undefined;
export default function tailwindIntegration(options?: TailwindOptions): AstroIntegration { export default function tailwindIntegration(options?: TailwindOptions): AstroIntegration {
const applyBaseStyles = options?.config?.applyBaseStyles ?? true; const applyBaseStyles = options?.applyBaseStyles ?? true;
const customConfigPath = options?.config?.path; const customConfigPath = options?.configFile;
return { return {
name: '@astrojs/tailwind', name: '@astrojs/tailwind',
hooks: { hooks: {