Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tailwind.config.ts support #483

Merged
merged 6 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions docs/content/2.setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ Discover your color palette based on your Tailwind config with the [Tailwind vie

## Tailwind Files

When running `nuxt dev`, this module will look for these two files:
When running `nuxt dev`, this module will look for these files:

- `./assets/css/tailwind.css`
- `./tailwind.config.js`
- `./tailwind.config.{js,ts}`

If they don't exist, the module will inject a basic configuration for each one so you don't have to create these files.

Expand All @@ -71,6 +71,33 @@ You can configure the paths in the [module options](/options).

Learn more about overwriting the Tailwind configuration in the [Tailwind Config](/tailwind/config) section.

## TypeScript

The module supports TypeScript Tailwind config, simply rename your `tailwind.config.js` to `tailwind.config.ts`.

A `defineTailwindConfig` decorator function which accepts `TailwindConfig` from [@types/tailwindcss](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/tailwindcss).

```ts
import { defineTailwindConfig } from '@nuxtjs/tailwindcss/config'

export default defineTailwindConfig({
theme: {
extend: {}
},
})
```

Note: You may need to enable `allowSyntheticDefaultImports` in your `tsconfig.json` if you have errors importing from Tailwind.

```json
{
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
```

## Options

You can customize the module's behavior by using the `tailwindcss` property in `nuxt.config`:
Expand Down
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,33 @@
".": {
"require": "./dist/module.cjs",
"import": "./dist/module.mjs"
},
"./config": {
"require": "./dist/config/index.cjs",
"import": "./dist/config/index.mjs",
"types": "./dist/config/index.d.ts"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"unbuild": {
"entries": [
harlan-zw marked this conversation as resolved.
Show resolved Hide resolved
{
"input": "src/config",
"outDir": "dist/config",
"builder": "mkdist",
"format":"cjs",
"ext": "cjs"
},
{
"input": "src/config",
"outDir": "dist/config",
"builder": "mkdist",
"format":"mjs",
"ext": "mjs"
}
]
},
"files": [
"dist"
],
Expand Down
5 changes: 5 additions & 0 deletions playground/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineTailwindConfig } from '../src/config'

export default defineTailwindConfig({
theme: {}
})
5 changes: 5 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TailwindConfig } from 'tailwindcss/tailwind-config'

export function defineTailwindConfig (config: TailwindConfig): TailwindConfig {
return config
}
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineNuxtModule({
configKey: 'tailwindcss'
},
defaults: nuxt => ({
configPath: 'tailwind.config.js',
configPath: 'tailwind.config',
harlan-zw marked this conversation as resolved.
Show resolved Hide resolved
cssPath: join(nuxt.options.dir.assets, 'css/tailwind.css'),
config: defaultTailwindConfig(nuxt.options),
viewer: true,
Expand Down
4 changes: 3 additions & 1 deletion src/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Learn more at https://tailwindcss.com/docs/configuration
export default ({ srcDir }) => ({
import { TailwindConfig } from 'tailwindcss/tailwind-config'
harlan-zw marked this conversation as resolved.
Show resolved Hide resolved

export default ({ srcDir }): TailwindConfig => ({
theme: {
extend: {}
},
Expand Down