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

怎么启用rpx 转px #24

Open
Rika-L opened this issue Sep 13, 2024 · 2 comments
Open

怎么启用rpx 转px #24

Rika-L opened this issue Sep 13, 2024 · 2 comments

Comments

@Rika-L
Copy link

Rika-L commented Sep 13, 2024

如题,官网的教程是基于cjs引入postcss-pxtransform的,现在用esm怎么引入

@sonofmagic
Copy link
Owner

好问题,现在这个项目实际上可以直接引入,因为这个 uni-app 项目实际上是直接在 vite.config.ts 里面内联的 postcss 插件,外面放个 postcss.config.ts 只是摆设而已。

你可以试试直接 import 或者 require, vite.config.ts 应该是做了这 2 种格式的处理的.

@Rika-L
Copy link
Author

Rika-L commented Sep 13, 2024

谢谢,这样写就可以了,之前没有类型提示,原来是用于测试的盒子宽高不相等

import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import type {AcceptedPlugin} from 'postcss'
import cssMacro from 'weapp-tailwindcss/css-macro/postcss'
import postcssPxtransform from 'postcss-pxtransform';

const plugins: AcceptedPlugin[] = [
  tailwindcss(), 
  autoprefixer(), 
  postcssPxtransform({platform: 'weapp', designWidth: 750})
]

plugins.push(cssMacro)


export default plugins

,顺带一提我也遇到了issues19相同问题,真机测试会爆红,不知道会不会对日后生产环境有影响

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