webpack打包vue文件報錯:Module parse failed: Unexpected token (1:0)


webpack 默認不能處理vue文件,需要安裝對應的load才可以

1.安裝vue-loader和vue-template-compiler

npm install vue-loader vue-template-compiler --save-dev

2.修改webpack.config.js

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

 

再次打包依然報錯

ERROR in 
vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin in your webpack config.

可能是因為vue-router 版本是15以上引起的

需要在webpack.config.js中添加如下配置

const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports  = {
    plugins: [   //插件配置
        new VueLoaderPlugin()
    ],
    module: {
      ......  
    }
};    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM