使用postcss-px-to-viewport适配时,网上搜的大多都是这种,但我运行后,发现根本找不到file,请问这是什么原因呢?
const path = require("path");
module.exports = ({ file }) => {
const designWidth = file.includes(path.join("node_modules", "vant")) ? 375 : 750;
return {
plugins: {
autoprefixer: {},
"postcss-px-to-viewport": {
unitToConvert: "px",
viewportWidth: designWidth,
unitPrecision: 6,
propList: ["*"],
viewportUnit: "vw",
fontViewportUnit: "vw",
selectorBlackList: [],
minPixelValue: 1,
mediaQuery: true,
exclude: [],
landscape: false,
},
},
};
};
const designWidth = file.includes(path.join("node_modules", "vant")) ? 375 : 750;
你这段nodejs
代码的目的就是判断 node_modules
下面是否存在 vant
文件夹?
可以换成 fs
的 api
实现
const fs = require('fs')
...
const vantDir = path.join("./node_modules", "vant") // 获取 vant 目录
const designWidth = fs.existsSync(vantDir) ? 375 : 750