webpack中引入vue組件(.vue文件)時打包報錯的解決辦法

如圖的錯誤:

一片紅,但是要仔細看出現了什麼錯誤,其中 vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin in your webpack config. 這一句很關鍵!!

錯誤中提示缺少了一個插件,webpack config 中缺少名爲 VueLoaderPlugin 的插件,意思就是 webpack的配置文件 webpack.config.js 中缺少了 VueLoaderPlugin 插件,因此只需要添加這個插件就可以了。

在添加之先引入插件:const VueLoaderPlugin = require("vue-loader/lib/plugin");

然後在 plugins 裏創建一個新的插件:plugins:[ new VueLoaderPlugin(); ]

像這樣:

之後你再打包,基本就沒有問題了,如果說還有問題,就看看是什麼問題,例如是 You may need an appropriate loader to handle this file type. 的問題,你要看看你的 引入 vue-loader 沒有,如果沒有,就引入:{ test:/\.vue$/, use:"vue-loader" }

這樣基本就能解決問題了!!

 

歡迎點贊!!點點關注~~