工程化解决前端xss攻击
2022-06-22 本文已影响0人
buffonme
npm isntall xss
编译前 通过vue-loader传入的compilerOptions.directives 与 baseOptions.directives 合并
chainWebpack: config => {
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap(options => {
options.compilerOptions.directives = {
html(node, directiveMeta) {
(node.props || (node.props = [])).push({
name: "innerHTML",
value: `xss(_s(${directiveMeta.value}))`
});
}
};
return options;
});
}