forked from jd-solanki/anu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(anu-nuxt): better support and config (jd-solanki#108)
- Loading branch information
1 parent
65d555d
commit 46a05b4
Showing
12 changed files
with
8,007 additions
and
5,838 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
{ | ||
"private": true, | ||
"name": "my-module-playground", | ||
"devDependencies": { | ||
"@iconify-json/bx": "^1.1.5", | ||
"@unocss/nuxt": "^0.46.5" | ||
}, | ||
"dependencies": { | ||
"@anu-vue/preset-theme-default": "workspace:*" | ||
} | ||
"name": "my-module-playground" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,5 @@ | ||
import { presetThemeDefault } from '@anu-vue/preset-theme-default' | ||
import type { UnocssNuxtOptions } from '@unocss/nuxt' | ||
import presetIcons from '@unocss/preset-icons' | ||
import presetUno from '@unocss/preset-uno' | ||
import { presetAnu } from 'anu-vue' | ||
|
||
export default <UnocssNuxtOptions>{ | ||
preflight: false, | ||
presets: [ | ||
presetUno(), | ||
presetIcons({ | ||
scale: 1.2, | ||
extraProperties: { | ||
'height': '1.5em', | ||
'flex-shrink': '0', | ||
'display': 'inline-block', | ||
}, | ||
}), | ||
|
||
// anu-vue presets | ||
presetAnu(), | ||
presetThemeDefault(), | ||
], | ||
include: [/.*\/anu-vue\.js(.*)?$/, './**/*.vue', './**/*.md'], | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,105 @@ | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import { presetThemeDefault } from '@anu-vue/preset-theme-default' | ||
import { | ||
addComponent, | ||
addImportsSources, | ||
addPlugin, | ||
createResolver, | ||
defineNuxtModule | ||
addPlugin, | ||
createResolver, | ||
defineNuxtModule, | ||
} from '@nuxt/kit' | ||
import presetIcons from '@unocss/preset-icons' | ||
import presetUno from '@unocss/preset-uno' | ||
import { presetAnu, presetIconExtraProperties } from 'anu-vue' | ||
|
||
import { name, version } from '../package.json' | ||
|
||
export interface ModuleOptions {} | ||
const configKey = 'anu' | ||
|
||
/** Nuxt Module Options */ | ||
interface PresetThemeOptions { | ||
|
||
/** | ||
* Import Anu Preset Theme with either CSS or SASS | ||
* You can either import CSS which doesn't require any additional setup | ||
* or SASS which requires you to install `sass` dependencies. | ||
* | ||
* @default 'css' | ||
*/ | ||
style?: 'css' | 'sass' | ||
} | ||
|
||
export interface ModuleOptions { | ||
|
||
/** | ||
* Import Anu Preset Theme Default | Source npm pkg: `@anu-vue/preset-theme-default` | ||
* When enabled, it will automatically set up the default presets for Anu and Uno. | ||
* We recommend to enable this option to get the best experience. | ||
* | ||
* @default true | ||
*/ | ||
presetTheme?: PresetThemeOptions | boolean | ||
} | ||
|
||
export default defineNuxtModule<ModuleOptions>({ | ||
defaults: { | ||
presetTheme: true, | ||
}, | ||
meta: { | ||
name, | ||
version, | ||
configKey: 'anuVue', | ||
configKey, | ||
compatibility: { | ||
nuxt: '^3.0.0', | ||
}, | ||
}, | ||
setup(moduleOptions, nuxt) { | ||
setup(opts, nuxt) { | ||
const { resolve } = createResolver(import.meta.url) | ||
|
||
nuxt.options.css.push('anu-vue/dist/style.css') | ||
|
||
if (opts.presetTheme === true || typeof opts.presetTheme === 'object') { | ||
nuxt.options.unocss = nuxt.options.unocss || {} | ||
|
||
const ext = typeof opts.presetTheme === 'object' ? opts.presetTheme.style : 'css' | ||
nuxt.options.css.push(`@anu-vue/preset-theme-default/dist/style.${ext}`) | ||
|
||
const iconPreset = !!nuxt.options.unocss?.icons || true | ||
nuxt.options.unocss.preflight = false | ||
|
||
// Add default presets for Anu into the unocss options. | ||
nuxt.options.unocss.presets = [ | ||
// @ts-expect-error - We know that is a valid preset | ||
presetUno(), | ||
|
||
// @ts-expect-error - We know that is a valid preset | ||
presetAnu(), | ||
|
||
// @ts-expect-error - We know that is a valid preset | ||
presetThemeDefault(), | ||
...(nuxt.options.unocss.presets || []), | ||
] | ||
|
||
// If icon preset is enabled via `unocss.icons` option, add it to the presets. | ||
// Default to `true` if `unocss.icons` is not defined. | ||
if (iconPreset) { | ||
// Icon Preset Anu by default | ||
const presetIcon = presetIcons(typeof iconPreset === 'object' | ||
? iconPreset | ||
: { | ||
scale: 1.2, | ||
extraProperties: presetIconExtraProperties, | ||
}, | ||
) | ||
|
||
// @ts-expect-error - We know that is a valid preset | ||
nuxt.options.unocss.presets?.push(presetIcon) | ||
} | ||
} | ||
|
||
nuxt.hook('prepare:types', ({ tsConfig, references }) => { | ||
tsConfig.compilerOptions!.types.push('anu-vue/volar') | ||
references.push({ | ||
path: resolve(nuxt.options.buildDir, 'types/anu-vue.d.ts'), | ||
types: 'anu-vue/volar', | ||
}) | ||
}) | ||
|
||
addPlugin({ src: resolve('./runtime/plugin') }) | ||
|
||
// Add auto-imported components | ||
anuComponentNames.map(name => | ||
addComponent({ | ||
name, | ||
export: name, | ||
filePath: 'anu-vue', | ||
}), | ||
) | ||
|
||
addImportsSources([ | ||
{ | ||
from: 'anu-vue', | ||
imports: anuComposables, | ||
}, | ||
]) | ||
}, | ||
}) | ||
|
||
const anuComponentNames = [ | ||
'AAlert', | ||
'AAvatar', | ||
'ABadge', | ||
'ABaseInput', | ||
'ABtn', | ||
'ACard', | ||
'ACheckbox', | ||
'AChip', | ||
'ADataTable', | ||
'ADialog', | ||
'ADrawer', | ||
'AInput', | ||
'AList', | ||
'AListItem', | ||
'AMenu', | ||
'ARadio', | ||
'ARating', | ||
'ASelect', | ||
'ASwitch', | ||
'ATable', | ||
'ATextarea', | ||
'ATypography', | ||
] | ||
|
||
const anuComposables = [ | ||
'useConfigurable', | ||
'useDOMScrollLock', | ||
'useGroupModel', | ||
'useInternalBooleanState', | ||
'useLayer', | ||
'useSearch', | ||
'useSort', | ||
'useSpacing', | ||
'useTeleport', | ||
// 'useProps', | ||
] | ||
|
||
declare module '@nuxt/schema' { | ||
interface ConfigSchema { | ||
runtimeConfig: { | ||
public?: { | ||
anu?: ModuleOptions | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.