Skip to content

Commit

Permalink
feat: add option to set cssPath to false (#544)
Browse files Browse the repository at this point in the history
Co-authored-by: Younho Choo <yo+github@younho9.com>
Co-authored-by: Sébastien Chopin <seb@nuxtlabs.com>
  • Loading branch information
younho9 and Atinux committed Oct 21, 2022
1 parent 9d6fae3 commit f45fc97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/content/1.getting-started/2.options.md
Expand Up @@ -33,6 +33,20 @@ export default {

This file will be directly injected as a [global CSS](https://v3.nuxtjs.org/api/configuration/nuxt.config#css) for Nuxt. It supports `css`, `sass`, `postcss`, and more.

If you don't want to inject CSS file, you can set `cssPath` to `false`.

```ts [nuxt.config]
export default {
tailwindcss: {
cssPath: false,
}
}
```

::alert{type="warning"}
When set to `false`, note that HMR for tailwindcss will be broken (hard refresh needed).
::

## `configPath`

- Default: `'tailwind.config'`
Expand Down
7 changes: 5 additions & 2 deletions src/module.ts
Expand Up @@ -43,7 +43,7 @@ type Arrayable<T> = T | T[]

export interface ModuleOptions {
configPath: Arrayable<string>;
cssPath: string;
cssPath: string | false;
config: Config;
viewer: boolean;
exposeConfig: boolean;
Expand Down Expand Up @@ -170,7 +170,7 @@ export default defineNuxtModule<ModuleOptions>({
* CSS file handling
*/

const cssPath = await resolvePath(moduleOptions.cssPath, { extensions: ['.css', '.sass', '.scss', '.less', '.styl'] })
const cssPath = typeof moduleOptions.cssPath === 'string' ? await resolvePath(moduleOptions.cssPath, { extensions: ['.css', '.sass', '.scss', '.less', '.styl'] }) : false

// Include CSS file in project css
let resolvedCss: string
Expand All @@ -183,6 +183,9 @@ export default defineNuxtModule<ModuleOptions>({
// @ts-ignore
resolvedCss = createResolver(import.meta.url).resolve('runtime/tailwind.css')
}
} else {
logger.info('No Tailwind CSS file found. Skipping...')
resolvedCss = createResolver(import.meta.url).resolve('runtime/empty.css')
}
nuxt.options.css = nuxt.options.css ?? []
const resolvedNuxtCss = await Promise.all(nuxt.options.css.map(p => resolvePath(p)))
Expand Down
Empty file added src/runtime/empty.css
Empty file.

0 comments on commit f45fc97

Please sign in to comment.