Nuxt UI without app.config.ts

Defining primary color via the app.config.ts lets us change the theme of our app at runtime (the palette button in the docs, also noted in the screenshot. My understanding is that app.config.ts provide the means to change our theme at runtime. But, I'm not really interested in changing my theme at runtime. Rather, I want to define a primary color and be able to use it in my default theme and for the color prop in various components. How can I achieve this in Nuxt UI? Is it possible to define primary color apart from the app.config.ts way, may be under the ui key in nuxt.config.ts itself? I have the same question about overriding component config also via app.config.ts. Please correct me if I'm misunderstanding the purpose and usage of app.config.ts. Thanks!
No description
5 Replies
kapa.ai
kapa.ai4w ago
Hi @TechAkayy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You're right that app.config.ts allows for runtime configuration changes, but it's not the only way to define your primary color and component configurations in Nuxt UI. Let me clarify and provide some alternatives based on the information from the knowledge sources: 1. Defining primary color without app.config.ts: You can define your primary color directly in your tailwind.config.ts file. This approach sets the color at build time rather than runtime. Here's how you can do it: Getting-started > Structure provides an example:
import type { Config } from 'tailwindcss'
import defaultTheme from 'tailwindcss/defaultTheme'

export default <Partial<Config>>{
theme: {
extend: {
colors: {
primary: {
50: '#EFFDF5',
100: '#D9FBE8',
200: '#B3F5D1',
300: '#75EDAE',
400: '#00DC82',
500: '#00C16A',
600: '#00A155',
700: '#007F45',
800: '#016538',
900: '#0A5331',
950: '#052e16'
}
}
}
}
}
import type { Config } from 'tailwindcss'
import defaultTheme from 'tailwindcss/defaultTheme'

export default <Partial<Config>>{
theme: {
extend: {
colors: {
primary: {
50: '#EFFDF5',
100: '#D9FBE8',
200: '#B3F5D1',
300: '#75EDAE',
400: '#00DC82',
500: '#00C16A',
600: '#00A155',
700: '#007F45',
800: '#016538',
900: '#0A5331',
950: '#052e16'
}
}
}
}
}
This method allows you to use your primary color in Tailwind classes and in Nuxt UI components that accept a color prop. 2. Overriding component config: While app.config.ts is the recommended way to override component configurations, you can also do this in nuxt.config.ts using the ui key. However, this is not as flexible as using app.config.ts. Getting-started > Options shows how to configure options in nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
// You can override some global UI settings here
// For example:
safelistColors: ['primary']
}
})
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
// You can override some global UI settings here
// For example:
safelistColors: ['primary']
}
})
However, this method is more limited and doesn't allow for the same level of component-specific customization that app.config.ts provides. 3. Purpose of app.config.ts: You're correct that one of the main purposes of app.config.ts is to allow for runtime configuration changes. However, it's also used for setting up your initial configuration, even if you don't plan to change it at runtime. Docs > Guide > Directory-structure > app-config explains: "The app.config.ts file, located in the source directory (by default the root of the project), is used to expose public variables that can be determined at build time. Contrary to the runtimeConfig option, these can not be overridden using environment variables." So, while app.config.ts allows for runtime changes, it's also a convenient place to set up your initial UI configuration, including your primary color and component overrides, even if you don't plan to change them later. In conclusion, while you can define your primary color in tailwind.config.ts and some global UI settings in nuxt.config.ts, using app.config.ts is still the recommended and most flexible way to configure Nuxt UI, even if you don't plan to change the configuration at runtime. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@755392946471305256> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
TechAkayy
TechAkayyOP4w ago
Nuxt
Configuration · Get Started with Nuxt
Nuxt is configured with sensible defaults to make you productive.
kapa.ai
kapa.ai4w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You're absolutely correct, and I apologize for the confusion in my previous response. Thank you for pointing that out. Let me provide you with the correct information based on the source you've mentioned. Docs > Getting-started > Configuration > App Configuration is indeed the correct link for information about the app.config.ts file in Nuxt. This document explains that the app.config.ts file is used to expose public variables that can be determined at build time. It's located in the source directory (by default, the root of the project). Here's an example of how you can use app.config.ts:
export default defineAppConfig({
title: 'Hello Nuxt',
theme: {
dark: true,
colors: {
primary: '#ff0000'
}
}
})
export default defineAppConfig({
title: 'Hello Nuxt',
theme: {
dark: true,
colors: {
primary: '#ff0000'
}
}
})
The variables defined in app.config.ts can be accessed in your application using the useAppConfig composable. It's important to note that, unlike runtimeConfig, the values in app.config.ts cannot be overridden using environment variables. This makes app.config.ts suitable for configuration that you want to set at build time and don't need to change based on the environment. Thank you for the correction. It's crucial to provide accurate information, and I appreciate your attention to detail. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@755392946471305256> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?