【问题标题】:VueLoaderPlugin Error: No matching use for vue-loader is foundVueLoaderPlugin 错误:找不到 vue-loader 的匹配用途
【发布时间】:2020-01-15 16:22:38
【问题描述】:

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

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

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

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 规则。这是什么问题,我该如何解决?

【问题讨论】:

  • 我在尝试制作 vue-styleguidist 时遇到了同样的问题(相同的 webpack 配置)
  • 查看 vue-loader 设置手册 https://vue-loader.vuejs.org/guide/#manual-setup 主要区别是导入/需要 vue-loader 本身而不是 vue-loader/lib/plugin

标签: webpack


【解决方案1】:

你的 Laravel 混合设置已经隐式加载了 VueLoaderPlugin,所以再次重新加载它会导致这个错误。

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

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

【讨论】:

    【解决方案2】:

    如何将配置文件中的导入重写为:
    const { VueLoaderPlugin } = require("vue-loader");

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 2020-12-09
      • 2020-11-18
      • 2020-01-29
      • 2021-08-24
      • 2021-01-06
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多