Skip to content
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
11 changes: 6 additions & 5 deletions playground/components/basic-demos/icon/demo.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<script setup lang="ts">
import {
HomeOutlined,
LoadingOutlined,
SettingFilled,
SmileOutlined,
LoadingOutlined,
SyncOutlined,
HeartFilled,
} from '@antdv-next/icons'
</script>

<template>
<a-space>
<a-space wrap>
<HomeOutlined />
<SettingFilled />
<SmileOutlined />
<SyncOutlined spin />
<SmileOutlined :rotate="180" />
<LoadingOutlined />
<SettingFilled />
<SyncOutlined spin />
<HeartFilled />
</a-space>
</template>
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export default defineNuxtConfig({
compatibilityDate: 'latest',
antd: {
icon: true,
component: true,
},
})
90 changes: 58 additions & 32 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import icons from './runtime/icons'

// Module options TypeScript interface definition
export interface ModuleOptions {
/**
* Enable components
* @default true
*/
component?: boolean
/**
* Enable icons
* @default false
*/
icon?: boolean
/**
* Components to be included or excluded
Expand Down Expand Up @@ -43,9 +52,15 @@ export default defineNuxtModule<ModuleOptions>({
// Default configuration options of the Nuxt module
defaults: {
icon: false,
component: true,
prefix: 'A',
},
setup(_options, _nuxt) {
// Skip if both components and icons are disabled
if (_options.component === false && _options.icon !== true) {
return
}

const transpileList = _nuxt.options.build.transpile
const appendTranspile = (dep: string) => {
if (!transpileList.includes(dep)) {
Expand All @@ -55,38 +70,45 @@ export default defineNuxtModule<ModuleOptions>({

// Keep icon definition modules in Nuxt transform pipeline to avoid
// cold-start interop inconsistency in dev SSR/hydration.
appendTranspile(libName)
if (_options.component !== false) {
appendTranspile(libName)
}

// Always transpile icon libs because users may import icons directly
appendTranspile(iconLibName)
appendTranspile(iconsSvgLibName)

const componentMap = {
QRCode: 'Qrcode',
}
// Filter components based on include/exclude options
const filteredComponents = components.filter((comp) => {
if (_options.include?.length) {
return _options.include.includes(comp)
// Register components
if (_options.component !== false) {
const componentMap = {
QRCode: 'Qrcode',
}
if (_options.exclude?.length) {
return !_options.exclude.includes(comp)
}
return true
})
// Filter components based on include/exclude options
const filteredComponents = components.filter((comp) => {
if (_options.include?.length) {
return _options.include.includes(comp)
}
if (_options.exclude?.length) {
return !_options.exclude.includes(comp)
}
return true
})

filteredComponents.forEach((comp) => {
let _comp: string = comp
if (comp in componentMap) {
_comp = componentMap[comp as keyof typeof componentMap]
}
addComponent({
filePath: 'antdv-next',
export: comp,
name: _options.prefix + _comp,
filteredComponents.forEach((comp) => {
let _comp: string = comp
if (comp in componentMap) {
_comp = componentMap[comp as keyof typeof componentMap]
}
addComponent({
filePath: 'antdv-next',
export: comp,
name: _options.prefix + _comp,
})
})
})
}

if (_options.icon !== false) {
appendTranspile(iconLibName)
// Register icons
if (_options.icon === true) {
// Filter icons based on include/exclude options
const filteredIcons = icons.filter((icon) => {
if (_options.includeIcons?.length) {
Expand All @@ -105,15 +127,19 @@ export default defineNuxtModule<ModuleOptions>({
})
})
}
const resolver = createResolver(import.meta.url)

// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve('./runtime/plugin'))
addServerPlugin(resolver.resolve('./runtime/server'))
// Only add plugins when components are enabled
if (_options.component !== false) {
const resolver = createResolver(import.meta.url)

// Check if the builder is Vite
if (_nuxt.options.builder === '@nuxt/vite-builder') {
addVitePlugin(dayjs())
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve('./runtime/plugin'))
addServerPlugin(resolver.resolve('./runtime/server'))

// Check if the builder is Vite
if (_nuxt.options.builder === '@nuxt/vite-builder') {
addVitePlugin(dayjs())
}
}
},
})
Loading