@zakijs/plugin-compiler-alipay
Version:
mor complier plugin for alipay mini program
37 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@morjs/utils");
const constants_1 = require("../constants");
const UNSUPPORT_SELECTOR_REGEXP = /(\s+[>|+]\s+)|\*|\~/;
/**
* 支付宝 样式 文件转译
*/
class AlipayCompilerStyleParserPlugin {
constructor() {
this.name = 'AlipayCompilerStyleParserPlugin';
}
apply(runner) {
runner.hooks.beforeRun.tap(this.name, () => {
const { sourceType, target } = runner.userConfig;
// 仅当 样式文件 是 支付宝 源码 且 编译目标不是 支付宝小程序 时执行该插件
if (sourceType !== utils_1.SourceTypes.alipay)
return;
if (sourceType === target)
return;
if ((0, constants_1.isSimilarTarget)(target))
return;
runner.hooks.styleParser.tap(this.name, (plugins, options) => {
return plugins.concat((0, utils_1.cssProcessorFactory)(this.name, (root) => {
root.walkRules((rule) => {
if (rule.selectors.filter((selector) => UNSUPPORT_SELECTOR_REGEXP.test(selector)).length) {
utils_1.logger.warnOnce(`当前编译目标 ${target} 中的样式 不支持 "> * + ~" 等选择器\n` +
`文件路径: ${options.fileInfo.path}`);
}
});
}));
});
});
}
}
exports.default = AlipayCompilerStyleParserPlugin;
//# sourceMappingURL=StyleParserPlugin.js.map