Hotline:15911225507
Long Xiao
Login
Home-All Posts-Nuxt.js英文,Vue.js英文-Main Content

Naive UI Integration & UnoCSS Atomic CSS in Nuxt 4

LXLX
Nuxt.js英文, Vue.js英文
2 months ago
0
0
3.59K
A practical guide to integrating Naive UI with UnoCSS in Nuxt 4, covering automatic imports, SSR style collection, Vite build optimization, and code-splitting strategies to achieve zero manual imports and on-demand loading for an exceptional developer experience.
A practical guide to integrating Naive UI with UnoCSS in a large-scale Nuxt 4 production project

1. Why Naive UI + UnoCSS?

DimensionNaive UIUnoCSS
RoleEnterprise Vue 3 component libraryOn-demand atomic CSS engine
Bundle SizeTree-shakingZero runtime
TypeScriptNative TSType-safe presets
ThemingLight/dark themesShares Naive UI variables
SSR@css-render/vue3-ssrInline CSS, zero overhead

2. Naive UI Auto-Import

plugins: [
    AutoImport({
        imports: [{
            'naive-ui': ['createDiscreteApi', 'useOsTheme', 'useMessage', 'useDialog',
                'lightTheme', 'darkTheme', 'zhCN', 'zhTW', 'dateZhCN', 'dateZhTW']
        }]
    }),
    Components({ resolvers: [NaiveUiResolver()] })
]
{ "dependencies": { "@css-render/vue3-ssr": "^0.15.14" } }
build: { transpile: ['naive-ui', 'vueuc', 'radash'] }

Global Discrete API Injection

const { message, dialog } = createDiscreteApi(['message', 'dialog'])
;(globalThis as any).__salongMessage = message

3. UnoCSS Architecture

unocss: { nuxtLayers: true }

CSS division of labor:

  • Naive UI theme variables → custom.scss
  • Global layout/reset → main.scss
  • Component styling → UnoCSS atomic classes

4. Vite Optimization

vite: {
    optimizeDeps: { include: ['naive-ui', 'vueuc', 'dayjs', 'dompurify', ...] },
    build: {
        minify: 'esbuild', cssMinify: true, assetsInlineLimit: 4096,
        rollupOptions: {
            output: {
                manualChunks(id) {
                    if (id.includes('node_modules/@vue-office')) {
                        const pkg = id.match(/@vue-office\\/([^/]+)/)?.[1]
                        return pkg ? `vue-office-${pkg}` : 'vue-office'
                    }
                }
            }
        }
    }
}

5. Summary

  1. Zero manual imports: AutoImport + NaiveUiResolver
  2. Unified theming: Naive UI variables → UnoCSS shortcuts → SCSS overrides
  3. SSR-friendly: @css-render/vue3-ssr + esbuild minification
Tags:
本文原创,作者:龙霄,其版权均为龙霄所有。如需转载,请注明出处:https://lx.yfdxs.com/en/1429.html
LX

LX

Lv1Rec2
Revitalize the WordPress experience with the power of Nuxt.js
219.25W1119
Loading...
Share:
1
Nuxt 4 i18n Architecture & Multi-Language Routing Strategy
Nuxt 4 i18n Architecture & Multi-Language Routing StrategyPrevious
Pinia State Persistence & Memory Governance in Nuxt 4Next
Pinia State Persistence & Memory Governance in Nuxt 4
相关文章
Total: 17
Nuxt 4 i18n Architecture & Multi-Language Routing Strategy

Nuxt 4 i18n Architecture & Multi-Language Routing Strategy

Acompleteguidetoathree-language(zh-CN/zh-TW/en)i18nsetupwith@n…
LXLX
Nuxt.js英文, Vue.js英文
2 months ago
0
0
2.65K
0
Nuxt.js + WordPress Architecture: A Comprehensive Guide to Performance, Speed, Security, and Caching

Nuxt.js + WordPress Architecture: A Comprehensive Guide to Performance, Speed, Security, and Caching

WhenNuxt.js'smodernfrontendengineeringcapabilitiesmeetWordPress's…
LXLX
Nuxt.js英文, WordPress英文
2 months ago
0
0
4.22K
0
Embracing Modern Web Development: The Nuxt.js + WordPress Architectural Revolution

Embracing Modern Web Development: The Nuxt.js + WordPress Architectural Revolution

一、PerformanceOptimization:ThePerfectBalanceofStaticGenerationand…
LXLX
Nuxt.js英文, WordPress英文
2 months ago
0
0
2.91K
0
Longxiao Theme-Visual Page Builder: Build Professional-Grade Websites in One Afternoon

Longxiao Theme-Visual Page Builder: Build Professional-Grade Websites in One Afternoon

Saygoodbyetothetraditionalwebsitebuildingworkflowofwritingcode…
LXLX
Nuxt.js英文, WordPress英文
2 months ago
0
0
2.56K
0
Pinia State Persistence & Memory Governance in Nuxt 4

Pinia State Persistence & Memory Governance in Nuxt 4

Asystematicwalkthroughofstatemanagementacross25PiniaStoresina…
LXLX
Nuxt.js英文, Vue.js英文
2 months ago
0
0
4.80K
0
Longxiao Theme-Knowledge Payment Course Plugin: Core Features and Learning Engagement Strategies

Longxiao Theme-Knowledge Payment Course Plugin: Core Features and Learning Engagement Strategies

Intheeraoftheknowledgeeconomy,howdoyoutransformprofessionale…
LXLX
Nuxt.js英文, WordPress英文
2 months ago
0
0
2.73K
0
Data Caching Optimization Strategies for Nuxt.js Headless WordPress Projects

Data Caching Optimization Strategies for Nuxt.js Headless WordPress Projects

InaHeadlessWordPress+Nuxt.jsarchitecture,WordPressservesasthe…
LXLX
Nuxt.js英文, WordPress英文
4 days ago
0
0
15
0
Longxiao Theme – E-Commerce Platform: A Unified Transaction Engine for Course, Physical Product, and Event Marketing Plugins

Longxiao Theme – E-Commerce Platform: A Unified Transaction Engine for Course, Physical Product, and Event Marketing Plugins

Oneunderlyingtransactionpipeline,threeproducttypes,unifiedshoppi…
LXLX
Nuxt.js英文
2 months ago
0
0
2.62K
0
One-Click Intelligence, Trilingual Mastery: How LongXiao AI Translation Doubles Your Multilingual Site Management Efficiency

One-Click Intelligence, Trilingual Mastery: How LongXiao AI Translation Doubles Your Multilingual Site Management Efficiency

I.ThePainPoints:ThreeMountainsofMultilingualWebsiteManagement…
LXLX
Nuxt.js英文, Vue.js英文, WordPress英文
1 months ago
0
0
52
0
Longxiao Theme-E-Commerce & Membership Integrated Product Plugin: Turn Content Monetization from [Can Sell] to [Sells Well]

Longxiao Theme-E-Commerce & Membership Integrated Product Plugin: Turn Content Monetization from [Can Sell] to [Sells Well]

Acompletee-commercetransactionpipelinepairedwithamulti-tiermemb…
LXLX
Nuxt.js英文, WordPress英文
2 months ago
0
0
2.74K
0
LongXiao Theme Affiliate System: Frontend Tracking, Multi-Language Support, and the Full Pipeline from Traffic to Commission

LongXiao Theme Affiliate System: Frontend Tracking, Multi-Language Support, and the Full Pipeline from Traffic to Commission

IntroductionInthedigitalbusinessecosystem,affiliatemarketingh…
LXLX
Nuxt.js英文, Vue.js英文
9 days ago
0
0
27
0
LongXiao Theme Four Little Monsters Guarding the Login: A Deep Dive into Playful Interaction Design

LongXiao Theme Four Little Monsters Guarding the Login: A Deep Dive into Playful Interaction Design

Theypeekwhenyoutypeyourpassword.Theytilttheirheadstofollowy…
LXLX
Nuxt.js英文, Vue.js英文
2 months ago
0
0
4.50K
0
评论表单游客 您好,欢迎参与讨论。
Loading...
评论列表
Total: 0
Long Xiao
No relevant content