Skip to content

Commit

Permalink
fix(presets): 同步打包目标
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Dec 29, 2023
1 parent 2d51141 commit 3e72542
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
10 changes: 2 additions & 8 deletions presets/autoprefixer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { cwd } from 'process'
import type { Preset } from 'unocss'
import browserslist from 'browserslist'
import { defaultBuildTargets } from './shared/detect'
import { browserslistToTargets, transformStyleAttribute } from 'lightningcss'

const { loadConfig: browserslistLoadConfig } = browserslist

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

export default function autoprefixerPreset(
targets: string[] = defaultTargets,
targets: string[] = defaultBuildTargets,
): Preset {
return {
name: 'unocss-preset-autoprefixer',
Expand Down
5 changes: 4 additions & 1 deletion presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type { ComponentResolver } from 'unplugin-vue-components/types'

// 内置插件
import { Alias, Restart, Warmup } from './plugins'
import { defaultBuildTargets } from './shared/detect'

export const _dirname = dirname(fileURLToPath(import.meta.url))

Expand All @@ -59,7 +60,9 @@ export default function () {
* 兼容不支持 esmModule 的浏览器
* https://www.npmjs.com/package/@vitejs/plugin-legacy
*/
Legacy(),
Legacy({
targets: defaultBuildTargets,
}),
/**
* 环境变量类型提示
* https://github.com/dishait/vite-plugin-env-types
Expand Down
16 changes: 16 additions & 0 deletions presets/shared/detect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 侦察模块
* @description 自动检测环境并智能生成
*/

import { cwd } from 'process'
import browserslist from 'browserslist'

const { loadConfig: browserslistLoadConfig } = browserslist

/**
* 默认打包目标 (浏览器兼容程度)
*/
export const defaultBuildTargets = browserslistLoadConfig({ path: cwd() }) || [
'last 2 versions and not dead, > 0.3%, Firefox ESR',
]

0 comments on commit 3e72542

Please sign in to comment.