From c4672fe3342547e70691ff18a0cdf35f9d190062 Mon Sep 17 00:00:00 2001 From: liushilong <2224574157@qq.com> Date: Mon, 25 Mar 2024 10:17:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=A8=E5=B1=80=E8=87=AA=E9=80=82?= =?UTF-8?q?=E5=BA=941440UI=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .postcssrc.js | 44 ++++++++++++++++++++++++++++++++++ package.json | 2 ++ src/App.vue | 65 +++++++++++++++++++++++++++++++-------------------- src/main.ts | 1 + 4 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 .postcssrc.js diff --git a/.postcssrc.js b/.postcssrc.js new file mode 100644 index 0000000..bd4534a --- /dev/null +++ b/.postcssrc.js @@ -0,0 +1,44 @@ +/** + * PostCSS 配置文件 + */ + +module.exports = { + // 配置要使用的 PostCSS 插件 + plugins: { + // 配置使用 autoprefixer 插件 + // 作用:生成浏览器 CSS 样式规则前缀 + // VueCLI 内部已经配置了 autoprefixer 插件 + // 所以又配置了一次,所以产生冲突了 + // 'autoprefixer': { // autoprefixer 插件的配置 + // 配置要兼容到的环境信息 + // browsers: ['Android >= 4.0', 'iOS >= 8'] + // }, + + // 配置使用 postcss-pxtorem 插件 + // 作用:把 px 转为 rem + 'postcss-pxtorem': { + // lib-flexible 的 REM 适配方案:把一行分为 10 份,每份就是十分之一 + // 所以 rootValue 应该设置为你的设计稿宽度的十分之一 + // 我们的设计稿是 750,所以应该设置为 750 / 10 = 75 + // 但是 Vant 建议设置为 37.5,为什么?因为 Vant 是基于 375 写的 + // 所以必须设置为 37.5,唯一的缺点就是使用我们设计稿的尺寸都必须 / 2 + // 有没有更好的办法? + // 如果是 Vant 的样式,就按照 37.5 来转换 + // 如果是 我们自己 的样式,就按照 75 来转换 + // 通过查阅文档,我们发现 rootValue 支持两种类型: + // 数字:固定的数值 + // 函数:可以动态处理返回 + // postcss-pxtorem 处理每个 CSS 文件的时候都会来调用这个函数 + // 它会把被处理的 CSS 文件相关的信息通过参数传递给该函数 + // file : vant-button.css + // file : login.vue + mediaQuery: true, //媒体查询( @media screen 之类的)中不生效 + // unitPrecision: 5, //保留rem小数点多少位 + // selectorBlackList: [''], //则是一个对css选择器进行过滤的数组,比如你设置为['fs'],那例如fs-xl类名,里面有关px的样式将不被转换,这里也支持正则写法。 + rootValue: 16, + // 配置要转换的 CSS 属性 + // * 表示所有 + propList: ['*'] + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 36a4b15..5810400 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@types/node": "^18.17.1", "@types/sortablejs": "^1.15.7", "@vitejs/plugin-vue": "^4.5.0", + "amfe-flexible": "^2.2.1", "autoprefixer": "^10.4.13", "core-js": "^3.32.0", "dotenv": "^16.3.1", @@ -59,6 +60,7 @@ "less-loader": "^11.1.3", "lint-staged": "^13.1.2", "postcss": "^8.4.27", + "postcss-pxtorem": "^6.1.0", "rimraf": "^4.2.0", "sass": "^1.69.5", "tailwindcss": "^3.3.3", diff --git a/src/App.vue b/src/App.vue index 73d2274..a092b7a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,12 +1,12 @@