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(module): add option to disable global css styles #1266

Merged
merged 5 commits into from
Jan 23, 2024
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
13 changes: 7 additions & 6 deletions docs/content/1.getting-started/2.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ You can also add the following to your `.vscode/settings.json` to enable Intelli

## Options

| Key | Default | Description |
| ------------------------ | ---------------------- | ------------------------------------------------ |
| `prefix` | `u` | Define the prefix of the imported components. |
| `global` | `false` | Expose components globally. |
| `icons` | `['heroicons']` | Icon collections to load. |
| `safelistColors` | `['primary']` | Force safelisting of colors to need be purged. |
| Key | Default | Description |
|-----------------------|-----------------|-------------------------------------------------------------------------------------------------------------|
| `prefix` | `u` | Define the prefix of the imported components. |
| `global` | `false` | Expose components globally. |
| `icons` | `['heroicons']` | Icon collections to load. |
| `safelistColors` | `['primary']` | Force safelisting of colors to need be purged. |
| `disableGlobalStyles` | `false` | Disable [global CSS styles](https://github.com/nuxt/ui/blob/dev/src/runtime/ui.css) injected by the module. |

Configure options in your `nuxt.config.ts` as such:

Expand Down
11 changes: 9 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export interface ModuleOptions {
icons: CollectionNames[] | 'all' | IconsPluginOptions

safelistColors?: string[]
/**
* Disables the global css styles added by the module.
*/
disableGlobalStyles?: boolean
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -68,7 +72,8 @@ export default defineNuxtModule<ModuleOptions>({
defaults: {
prefix: 'U',
icons: ['heroicons'],
safelistColors: ['primary']
safelistColors: ['primary'],
disableGlobalStyles: false
},
async setup (options, nuxt) {
const { resolve } = createResolver(import.meta.url)
Expand All @@ -80,7 +85,9 @@ export default defineNuxtModule<ModuleOptions>({

nuxt.options.alias['#ui'] = runtimeDir

nuxt.options.css.push(resolve(runtimeDir, 'ui.css'))
if (!options.disableGlobalStyles) {
nuxt.options.css.push(resolve(runtimeDir, 'ui.css'))
}

// @ts-ignore
nuxt.hook('tailwindcss:config', function (tailwindConfig) {
Expand Down