1 Star 0 Fork 0

animalcoder/Vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
animalcoder 提交于 2020-03-23 09:59 +08:00 . Vue6
import postcss from 'postcss';
const OVERRIDABLE_RULES = ['keyframes', 'counter-style'];
const SCOPE_RULES = ['media', 'supports'];
function isOverridable (name) {
return ~OVERRIDABLE_RULES.indexOf(postcss.vendor.unprefixed(name.toLowerCase()));
}
function isScope (name) {
return ~SCOPE_RULES.indexOf(postcss.vendor.unprefixed(name.toLowerCase()));
}
function getScope (node) {
let current = node.parent;
const chain = [node.name.toLowerCase(), node.params];
do {
if (current.type === 'atrule' && isScope(current.name)) {
chain.unshift(current.name + ' ' + current.params);
}
current = current.parent;
} while (current);
return chain.join('|');
}
export default postcss.plugin('postcss-discard-overridden', () => {
return css => {
const cache = {};
const rules = [];
css.walkAtRules(node => {
if (isOverridable(node.name)) {
const scope = getScope(node);
cache[scope] = node;
rules.push({
node,
scope,
});
}
});
rules.forEach(rule => {
if (cache[rule.scope] !== rule.node) {
rule.node.remove();
}
});
};
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/animalcoder/Vue.git
git@gitee.com:animalcoder/Vue.git
animalcoder
Vue
Vue
master

搜索帮助