px调整倍数问题修复

This commit is contained in:
DESKTOP-VMMLSOQ\wangzg 2024-03-02 22:59:49 +08:00
parent cce1ddfa72
commit 1ed5af4681
3 changed files with 21 additions and 19 deletions

View File

@ -6,24 +6,25 @@ let pxRegExp = /\b(\d+(\.\d+)?)px\b/;
let pxGlobalRegExp = new RegExp(pxRegExp.source, 'g'); let pxGlobalRegExp = new RegExp(pxRegExp.source, 'g');
module.exports = postcss.plugin('postcss-px2rem', (option) => { module.exports = postcss.plugin('postcss-px2rem', (option) => {
let opt = Object.assign({ let opt = Object.assign({
scale: 0.5, scale: 0.5,
ignore: [] ignore: []
}, option) }, option)
return (root, result) => { return (root, result) => {
const ignore = opt.ignore || [] const file = root.source.input.file
const file = result.opts.from const ignore = opt.ignore || []
for (const ignoreElement of ignore) { for (const ignoreElement of ignore) {
if (file.indexOf(ignoreElement) >= 0) return const regExp = new RegExp(ignoreElement)
} if (regExp.test(file)) return
root.walkDecls(function(decl) { }
if (/px/.test(decl.value)) { root.walkDecls(function (decl) {
decl.value = decl.value.replace(pxGlobalRegExp, function(match, p1) { if (/px/.test(decl.value)) {
return p1 * opt.scale + 'px' decl.value = decl.value.replace(pxGlobalRegExp, function (match, p1) {
}) return p1 * opt.scale + 'px'
}
}) })
result.root = root }
}; })
result.root = root
};
}); });

View File

@ -63,6 +63,7 @@ export default {
</style> </style>
<style lang='less' scoped> <style lang='less' scoped>
.index { .index {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
overflow: hidden; overflow: hidden;

View File

@ -3,7 +3,7 @@ module.exports = {
plugins: [ plugins: [
require('./buildPlugins/pxresize')({ require('./buildPlugins/pxresize')({
scale: 0.5, scale: 0.5,
ignore: ['manager'] ignore: ['manager', 'node_modules']
}) })
] ]
}; };