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');
module.exports = postcss.plugin('postcss-px2rem', (option) => {
let opt = Object.assign({
scale: 0.5,
ignore: []
}, option)
let opt = Object.assign({
scale: 0.5,
ignore: []
}, option)
return (root, result) => {
const ignore = opt.ignore || []
const file = result.opts.from
for (const ignoreElement of ignore) {
if (file.indexOf(ignoreElement) >= 0) return
}
root.walkDecls(function(decl) {
if (/px/.test(decl.value)) {
decl.value = decl.value.replace(pxGlobalRegExp, function(match, p1) {
return p1 * opt.scale + 'px'
})
}
return (root, result) => {
const file = root.source.input.file
const ignore = opt.ignore || []
for (const ignoreElement of ignore) {
const regExp = new RegExp(ignoreElement)
if (regExp.test(file)) return
}
root.walkDecls(function (decl) {
if (/px/.test(decl.value)) {
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 lang='less' scoped>
.index {
width: 100vw;
height: 100vh;
overflow: hidden;

View File

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