VueLoaderPlugin 错误:找不到与 vue-loader 匹配的用法

VueLoaderPlugin 错误:找不到与 vue-loader 匹配的用法

问题描述:

我在 Laravel Mix 项目中使用 webpack.当我的 webpack.config.js 看起来像这样时,Webpack 可以正常工作:

I am using webpack within a Laravel Mix project. When my webpack.config.js looks like this, Webpack works without error:

module.exports = {
    module: {
        rules: [{ test: /\.vue$/, loader: 'vue-loader' }]
    }
}

但是当我像这样添加 VueLoaderPlugin 时:

But when I add VueLoaderPlugin like so:

const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = {
    module: {
        rules: [{ test: /\.vue$/, loader: 'vue-loader' }]
    },
    plugins: [
        // make sure to include the plugin for the magic
        new VueLoaderPlugin()
    ]
}

我收到此错误:

Error: [VueLoaderPlugin Error] No matching use for vue-loader is found.
Make sure the rule matching .vue files include vue-loader in its use.

这没有意义,因为我已经准备好包含 vue-loader 的 .vue 规则.这里有什么问题,我该如何解决?

Which doesn't make sense since I ready have a .vue rule that includes vue-loader. What is the problem here, and how do I resolve it?

您的 Laravel mix 设置已经隐式加载了 VueLoaderPlugin,因此再次重新加载会导致此错误.

The Laravel mix setup of yours already loads the VueLoaderPlugin implicitly, so reloading it again causes this error.

通过阅读他们的文档,它写道他们支持 .vue 文件编译,无需额外配置.

From reading their docs, it written that they support .vue file compilation without extra configuration.

如果您仍然不相信,请查看他们的内部网络包配置:https://www.github.com/JeffreyWay/laravel-mix/tree/master/src%2Fcomponents%2FVue.js并注意 VueLoaderPlugin 的使用.

If you're still not convinced, check out their internal web pack configuration: https://www.github.com/JeffreyWay/laravel-mix/tree/master/src%2Fcomponents%2FVue.js and notice the use of VueLoaderPlugin.