From f45fc97b87eb63acdf9568d917177322d957ac82 Mon Sep 17 00:00:00 2001 From: Younho Choo Date: Sat, 22 Oct 2022 07:12:40 +0900 Subject: [PATCH] feat: add option to set `cssPath` to `false` (#544) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Younho Choo Co-authored-by: Sébastien Chopin --- docs/content/1.getting-started/2.options.md | 14 ++++++++++++++ src/module.ts | 7 +++++-- src/runtime/empty.css | 0 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/runtime/empty.css diff --git a/docs/content/1.getting-started/2.options.md b/docs/content/1.getting-started/2.options.md index e2ef8d97..f57a1a47 100644 --- a/docs/content/1.getting-started/2.options.md +++ b/docs/content/1.getting-started/2.options.md @@ -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'` diff --git a/src/module.ts b/src/module.ts index 3f1b6913..a26b4fac 100644 --- a/src/module.ts +++ b/src/module.ts @@ -43,7 +43,7 @@ type Arrayable = T | T[] export interface ModuleOptions { configPath: Arrayable; - cssPath: string; + cssPath: string | false; config: Config; viewer: boolean; exposeConfig: boolean; @@ -170,7 +170,7 @@ export default defineNuxtModule({ * 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 @@ -183,6 +183,9 @@ export default defineNuxtModule({ // @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))) diff --git a/src/runtime/empty.css b/src/runtime/empty.css new file mode 100644 index 00000000..e69de29b