istanbuljs / babel-plugin-istanbul

A babel plugin that adds istanbul instrumentation to ES6 code
BSD 3-Clause "New" or "Revised" License
616 stars 72 forks source link

unable to instrument Vue template code when using vue-loader #273

Open trusktr opened 2 years ago

trusktr commented 2 years ago

I can't figure any combination of options that will make this work with vue-loader.

What happens is that the <script> of a Vue component is instrumented just fine (it is outputted by vue-loader as a separate file, then babel-loader catches it, but not any expressions in a <template>.

The output "files" for template end with extensions like .vue?vue&type=template&id=qufnai32n or similar.

This is what my config looks like:

// babel.config.js
const babelConfig = {
    plugins: [['babel-plugin-istanbul', {
        extension: ['.js', '.vue'],
        excludeNodeModules: false

    }]]
};

module.exports = babelConfig;
// webpack.config.js
//...
            {
                test: /\.vue$/,
                use: [
                    {
                        loader: 'vue-loader',
                        // Attempt to use Babel with babel-plugin-istanbul (this doesn't make any difference, removing produces the same result)
                        options: {
                            compiler: require('vue-template-babel-compiler')
                        }
                    }
                ]
            },
            {
                test: /\.js$/,
                use: {
                    loader: 'babel-loader'
                }
            },
// ...

I also tried changing

                test: /\.js$/,

to

                test: /(\.js$)|(\?vue&type=template)/,
                exclude: /node_modules(?!.*\.vue)/,

but that still didn't manage to get vue <template>s instrumented.

Any ideas?

SoybeanSun commented 5 months ago

any ideas now ?