Skip to content

Commit

Permalink
feat: more variable config for ui/db
Browse files Browse the repository at this point in the history
  • Loading branch information
AloisSeckar committed Dec 2, 2024
1 parent dce674f commit fbf3389
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,32 @@ More info comming soon...
## Configuration
It is possible to select which Nuxt modules will be activated in your project. All dependencies are being downloaded into local `node_modules`, but Nuxt build process will ensure only relevant packages will be bundled for production.

### UI
### UI preset
It is possible to pick from three options:
- `nuxt-ui` - full https://ui.nuxt.com/ via `@nuxt/ui` connector module **[RECOMMENDED]**
- `tailwind` - only https://tailwindcss.com/ via `@nuxtjs/tailwindcss` connector module
- `off` - no UI library **[DEFAULT]**
- `off` - no UI library preset **[DEFAULT]**

Set the value via `NUXT_PUBLIC_IGNIS_UI` env variable.
Set the value via `NUXT_PUBLIC_IGNIS_PRESET_UI` env variable.

### Database
Value other than `off` will override Optional modules setting.

### Database preset
It is possible to pick from three options:
- `neon` - https://neon.tech/ via `nuxt-neon` connector module **[RECOMMENDED]**
- `supabase` - https://supabase.com/ via `@nuxtjs/supabase` connector module
- `off` - no database module **[DEFAULT]**
- `off` - no database module preset **[DEFAULT]**

Set the value via `NUXT_PUBLIC_IGNIS_DB_PRESET` env variable.

Set the value via `NUXT_PUBLIC_IGNIS_DB` env variable.
Value other than `off` will override Optional modules setting.

### Optional modules
Currently, following modules are opinionated:
- `@nuxt/ui` - set `NUXT_PUBLIC_IGNIS_UI` to `true | false`
- `@nuxtjs/tailwindcss` - set `NUXT_PUBLIC_IGNIS_TAILWIND` to `true | false` (ignored if `NUXT_PUBLIC_IGNIS_UI=true`)
- `nuxt-neon` - set `NUXT_PUBLIC_IGNIS_NEON` to `true | false`
- `@nuxtjs/supabase` - set `NUXT_PUBLIC_IGNIS_SUPABASE` to `true | false`
- `@nuxtjs/i18n` - set `NUXT_PUBLIC_IGNIS_I18N` to `true | false`
- `@formkit/nuxt` - set `NUXT_PUBLIC_IGNIS_FORMKIT` to `true | false`
- `@nuxt/content` - set `NUXT_PUBLIC_IGNIS_CONTENT` to `true | false`
Expand Down
36 changes: 18 additions & 18 deletions features.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defu } from 'defu'
import { log } from './utils/consola'
import OpenProps from 'open-props'
import { log } from './utils/consola'

export function setFeatures() {
// list of optional extra features
let extras = [] as string[]
const extras = [] as string[]

// object for optional config that will be merged with global Nuxt config
// declared in nuxt.config.ts
Expand All @@ -14,23 +14,22 @@ export function setFeatures() {

// 1. default modules (mandatory)
nuxtConfig.modules.push(
'nuxt-time',
'nuxt-security',
'@nuxt/eslint',
'@nuxt/image',
'@pinia/nuxt',
'@vueuse/nuxt',
'nuxt-time',
'nuxt-security',
'@nuxt/eslint',
'@nuxt/image',
'@pinia/nuxt',
'@vueuse/nuxt',
)

// 2. optional modules

// ui
if (process.env.NUXT_PUBLIC_IGNIS_UI === 'nuxt-ui') {
const uiPreset = process.env.NUXT_PUBLIC_IGNIS_PRESET_UI
if (uiPreset === 'nuxt-ui' || (!uiPreset && process.env.NUXT_PUBLIC_IGNIS_UI === 'true')) {
nuxtConfig.modules.push('@nuxt/ui')
}
else {
// remove @nuxt/ui-specific components from resolution
// if module is not used
} else {
// remove @nuxt/ui-specific components from resolution if module is not used
nuxtConfig = defu({
vue: {
compilerOptions: {
Expand All @@ -40,16 +39,17 @@ export function setFeatures() {
}, nuxtConfig)

// evaluate separate Tailwind CSS module
if (process.env.NUXT_PUBLIC_IGNIS_UI === 'tailwind') {
if (uiPreset === 'tailwind' || (!uiPreset && process.env.NUXT_PUBLIC_IGNIS_TAILWIND === 'true')) {
nuxtConfig.modules.push('@nuxtjs/tailwindcss')
}
}

// database
if (process.env.NUXT_PUBLIC_IGNIS_DB === 'neon') {
const dbPreset = process.env.NUXT_PUBLIC_IGNIS_PRESET_DB
if (dbPreset === 'neon' || (!dbPreset && process.env.NUXT_PUBLIC_IGNIS_NEON === 'true')) {
// module definition
nuxtConfig.modules.push('nuxt-neon')
} else if (process.env.NUXT_PUBLIC_IGNIS_DB === 'supabase') {
} else if (dbPreset === 'supabase' || (!dbPreset && process.env.NUXT_PUBLIC_IGNIS_SUPABASE === 'true')) {
// module definition
nuxtConfig.modules.push('@nuxtjs/supabase')
// module-specific config key
Expand Down Expand Up @@ -100,9 +100,9 @@ export function setFeatures() {
}

let overview = 'Nuxt Ignis will start using following settings:\n'
overview += 'Modules: ' + nuxtConfig.modules.join(', ') + "\n"
overview += 'Modules: ' + nuxtConfig.modules.join(', ') + '\n'
if (extras.length > 0) {
overview += 'Extras: ' + extras.join(', ') + "\n"
overview += 'Extras: ' + extras.join(', ') + '\n'
}
log.info(overview)

Expand Down
13 changes: 10 additions & 3 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const nuxtConfig = defu(ignisFeatures, {
stylistic: true,
},
},

// app configuration
runtimeConfig: {
// nitro-only secret env-like variables go here
Expand All @@ -26,8 +26,15 @@ const nuxtConfig = defu(ignisFeatures, {
// NOTE: due to static-like nature of nuxt.config.ts file
// actual values MUST BE provided via .env file (or production equivalent)
ignis: {
ui: 'off', // nuxt-ui/tailwind/off
db: 'off', // neon/supabase/off
preset: {
ui: 'off', // nuxt-ui/tailwind/off
db: 'off', // neon/supabase/off
},
// individual modules
ui: false, // true/false
tailwind: false, // true/false (ignored, if ui=true)
neon: false, // true/false
supabase: false, // true/false
i18n: false, // true/false
formkit: false, // true/false
content: false, // true/false
Expand Down

0 comments on commit fbf3389

Please sign in to comment.