Skip to content

Commit

Permalink
chore(presets): 规范函数定义
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Sep 21, 2023
1 parent 25e26ca commit 4e20163
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions presets/autoprefixer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { cwd } from 'process'
import type { Preset } from 'unocss'
import browserslist from 'browserslist'
import { browserslistToTargets, transformStyleAttribute } from 'lightningcss'

const { loadConfig: browserslistLoadConfig } = browserslist

const defaultTargets = browserslistLoadConfig({ path: process.cwd() }) || [
const defaultTargets = browserslistLoadConfig({ path: cwd() }) || [
'last 2 versions and not dead, > 0.3%, Firefox ESR',
]

export default function autoprefixerPreset(
targets?: string[] = defaultTargets,
targets: string[] = defaultTargets,
): Preset {
return {
name: 'unocss-preset-autoprefixer',
Expand Down
14 changes: 8 additions & 6 deletions presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
VantResolver,
VarletUIResolver,
ViewUiResolver,
Vuetify3Resolver,
VueUseComponentsResolver,
Vuetify3Resolver,
} from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import Markdown from 'unplugin-vue-markdown/vite'
Expand All @@ -46,8 +46,8 @@ import Legacy from '@vitejs/plugin-legacy'
import Vue from '@vitejs/plugin-vue'
import Jsx from '@vitejs/plugin-vue-jsx'

import type { Plugin } from 'vite'
import type { ComponentResolver } from 'unplugin-vue-components/types'
import type { Plugin } from 'vite'

export const _dirname =
typeof __dirname !== 'undefined'
Expand Down Expand Up @@ -248,7 +248,6 @@ export default function () {
* https://github.com/unocss/unocss
*/
plugins.push(
// @ts-ignore
UnoCss({
safelist: env.VITE_APP_MARKDOWN ? safelist.split(' ') : undefined,
}),
Expand All @@ -268,7 +267,7 @@ function useEnv() {
return NODE_ENV || 'development'
}

const stringToBoolean = (v: string) => {
function stringToBoolean(v: string) {
return Boolean(v === 'true' || false)
}

Expand Down Expand Up @@ -299,7 +298,11 @@ interface Options {
onlyExist?: [Arrayable<ComponentResolver>, string][]
include?: ComponentResolver[]
}
export const normalizeResolvers = (options: Options = {}) => {

/**
* 规范化 resolvers
*/
export function normalizeResolvers(options: Options = {}) {
const { onlyExist = [], include = [] } = options

const existedResolvers = []
Expand All @@ -309,7 +312,6 @@ export const normalizeResolvers = (options: Options = {}) => {
existedResolvers.push(resolver)
}
}

existedResolvers.push(...include)

return existedResolvers
Expand Down

0 comments on commit 4e20163

Please sign in to comment.