Skip to content

Commit f45fc97

Browse files
younho9atinux
andauthored
feat: add option to set cssPath to false (#544)
Co-authored-by: Younho Choo <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 9d6fae3 commit f45fc97

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

docs/content/1.getting-started/2.options.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ export default {
3333

3434
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.
3535

36+
If you don't want to inject CSS file, you can set `cssPath` to `false`.
37+
38+
```ts [nuxt.config]
39+
export default {
40+
tailwindcss: {
41+
cssPath: false,
42+
}
43+
}
44+
```
45+
46+
::alert{type="warning"}
47+
When set to `false`, note that HMR for tailwindcss will be broken (hard refresh needed).
48+
::
49+
3650
## `configPath`
3751

3852
- Default: `'tailwind.config'`

src/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Arrayable<T> = T | T[]
4343

4444
export interface ModuleOptions {
4545
configPath: Arrayable<string>;
46-
cssPath: string;
46+
cssPath: string | false;
4747
config: Config;
4848
viewer: boolean;
4949
exposeConfig: boolean;
@@ -170,7 +170,7 @@ export default defineNuxtModule<ModuleOptions>({
170170
* CSS file handling
171171
*/
172172

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

175175
// Include CSS file in project css
176176
let resolvedCss: string
@@ -183,6 +183,9 @@ export default defineNuxtModule<ModuleOptions>({
183183
// @ts-ignore
184184
resolvedCss = createResolver(import.meta.url).resolve('runtime/tailwind.css')
185185
}
186+
} else {
187+
logger.info('No Tailwind CSS file found. Skipping...')
188+
resolvedCss = createResolver(import.meta.url).resolve('runtime/empty.css')
186189
}
187190
nuxt.options.css = nuxt.options.css ?? []
188191
const resolvedNuxtCss = await Promise.all(nuxt.options.css.map(p => resolvePath(p)))

src/runtime/empty.css

Whitespace-only changes.

0 commit comments

Comments
 (0)