Skip to content

Instantly share code, notes, and snippets.

@TrySound
Created September 3, 2016 10:39
Show Gist options
  • Save TrySound/a8d8f8566f870bd432ebbc24af45c0a4 to your computer and use it in GitHub Desktop.
Save TrySound/a8d8f8566f870bd432ebbc24af45c0a4 to your computer and use it in GitHub Desktop.
const postcss = require('postcss');
const plugin1 = postcss.plugin('test', () => {
return css => {
css.walkDecls(decl => {
if (decl.value === '10px') {
decl.cloneAfter({
value: '20px'
});
}
});
};
});
const plugin2 = postcss.plugin('test', () => {
return css => {
css.walkDecls(decl => {
if (decl.value === '10px') {
decl.cloneBefore({
value: '20px'
});
}
});
};
});
console.log('plugin1');
console.log(postcss([plugin1]).process('font-size: 10px;').css);
console.log('plugin2');
console.log(postcss([plugin2]).process('font-size: 10px;').css);
plugin1
font-size: 10px;font-size: 20px;
plugin2
font-size: 20px;
font-size: 10px;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment