Skip to content

feat: add option to set cssPath to false #544

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

Merged
merged 5 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions docs/content/1.getting-started/2.options.md
Original file line number Diff line number Diff line change
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.js'`
Expand Down
7 changes: 5 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 @@ -162,7 +162,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 @@ -175,6 +175,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.