postcss 8格式

This commit is contained in:
Wang Kejun 2022-07-12 11:39:06 +08:00
parent 29c48d1a4d
commit bb98bf39a8
1 changed files with 26 additions and 8 deletions

View File

@ -2,12 +2,30 @@
const postcss = require('postcss');
const Rpx2px = require('./rpx2px');
module.exports = postcss.plugin('postcss-rpx2px', function (options) {
return function (css, result) {
const oldCssText = css.toString();
const rpx2pxIns = new Rpx2px(options);
const newCssText = rpx2pxIns.generatePx(oldCssText);
const newCssObj = postcss.parse(newCssText);
result.root = newCssObj;
// module.exports = postcss.plugin('postcss-rpx2px', function (options) {
// return function (css, result) {
// const oldCssText = css.toString();
// const rpx2pxIns = new Rpx2px(options);
// const newCssText = rpx2pxIns.generatePx(oldCssText);
// const newCssObj = postcss.parse(newCssText);
// result.root = newCssObj;
// };
// });
module.exports = function (options) {
return {
postcssPlugin: 'postcss-rpx2px',
Once: function (css, { result, AtRule }) {
const oldCssText = css.toString();
const rpx2pxIns = new Rpx2px(options);
const newCssText = rpx2pxIns.generatePx(oldCssText);
const newCssObj = postcss.parse(newCssText);
result.root = newCssObj;
},
// Declaration(decl) {
// console.log(decl.toString());
// },
};
});
};
module.exports.postcss = true;