【发布时间】:2023-12-31 00:22:01
【问题描述】:
我在 TS 中使用 Vue3(最后一个 vue-cli)。
我想在 vue-loader 编译 .vue 文件时获取所有节点(vnodes)元素。 我需要读取节点属性并删除所有“数据测试”。
我已经尝试在 vue.config.js 中使用:
module.exports = {
chainWebpack: (config) => {
config.module
.rule('vue')
.use('vue-loader')
// .loader('vue-loader') // same with
.tap((options) => {
options.compilerOptions = {
...(options.compilerOptions || {}),
modules: [ // never enter here
{
preTransformNode(node) {
// if (process.env.NODE_ENV === 'production') {
const { attrsMap, attrsList } = node
console.log(node)
if (attrsMap['qa-id']) {
delete attrsMap['qa-id']
const index = attrsList.findIndex(
(x) => x.name === 'data-test'
)
attrsList.splice(index, 1)
}
// }
return node
}
}
]
}
return options
})
}
}
我知道转换是在 vue-template-compiler 中完成的。 如何进入编译钩子?
我曾尝试在模块中使用 preTransformNode 但失败了。
来源:
【问题讨论】:
标签: vue.js vuejs3 vue-loader