vue-loader was used without the corresponding plugin. VueLoaderPlugin问题解决

安装vue-loader
npm i vue-loader vue-template-compiler

配置loader
{test:/\.vue$/,use:['vue-loader']}

配置完成在使用webpack命令打包的时候却报错:
Module Error (from ./node_modules/vue-loader/lib/index.js): vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin in your webpack config.

原因
vue-loader14 以上的版本需要额外配置plugin

解决办法1
重新安装低版本的vue-loader
npm un vue-loader
npm i vue-loader@13 -D

解决办法二(推荐使用)
在webpack.config.js中配置plugin

1.在文件头部添加以下代码
const VueLoaderPlugin = require('vue-loader/lib/plugin');
2.跟module对象平级添加以下代码
plugins: [ new VueLoaderPlugin() ]

重新执行webpack命令,没有报错,.vue文件成功被编译打包

发布了3 篇原创文章 · 获赞 5 · 访问量 168

猜你喜欢

转载自blog.csdn.net/qq_44621394/article/details/104637571