Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unocss 的 @apply 指令写样式没有把 px 转换为 vw,正常写法是可以转换的 #19

Closed
qiangguoguo opened this issue Dec 20, 2023 · 3 comments

Comments

@qiangguoguo
Copy link

vite-project.zip
老哥麻烦看一下

@wswmsword
Copy link
Owner

需要您安装下 UnoCSS 的 PostCSS 插件:

npm add -D @unocss/postcss

PostCSS 配置文件中添加 UnoCSS 插件:

import mobile from 'postcss-mobile-forever'
import autoprefixer from 'autoprefixer'
+ import unocssPs from '@unocss/postcss';

export default () => {
  return {
    plugins: [
+       unocssPs(),
      autoprefixer(),
      mobile({
        // 页面最外层选择器,例如 “#app”,用于设置在桌面端和移动端横屏时的居中样式
        appSelector: '#app',
        // 应用基于该宽度进行开发,转换后的伸缩视图将会以该宽度的视图作为标准进行比例伸缩
        viewportWidth: (file) => file.includes("vant") ? 375 : 750,
        // 限制视口单位的最大宽度, 利用 min() 之类的 CSS 函数
        // maxDisplayWidth: 600,
        // 打开媒体查询模式,打开后将自动关闭 maxDisplayWidth
        enableMediaQuery: true,
      }),
    ],
  }
}

@wswmsword
Copy link
Owner

需要您安装下 UnoCSS 的 PostCSS 插件:

npm add -D @unocss/postcss

PostCSS 配置文件中添加 UnoCSS 插件:

import mobile from 'postcss-mobile-forever'
import autoprefixer from 'autoprefixer'
+ import unocssPs from '@unocss/postcss';

export default () => {
  return {
    plugins: [
+       unocssPs(),
      autoprefixer(),
      mobile({
        // 页面最外层选择器,例如 “#app”,用于设置在桌面端和移动端横屏时的居中样式
        appSelector: '#app',
        // 应用基于该宽度进行开发,转换后的伸缩视图将会以该宽度的视图作为标准进行比例伸缩
        viewportWidth: (file) => file.includes("vant") ? 375 : 750,
        // 限制视口单位的最大宽度, 利用 min() 之类的 CSS 函数
        // maxDisplayWidth: 600,
        // 打开媒体查询模式,打开后将自动关闭 maxDisplayWidth
        enableMediaQuery: true,
      }),
    ],
  }
}

UnoCSS 的 PostCSS 插件链接:https://unocss.dev/integrations/postcss

@qiangguoguo
Copy link
Author

可以了,非常感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants