vue-loader 升级到版本v15问题记录

2019-11-27
JavaScript
5482

vue-loader 升级到最新的版本v15 之后,会报错如下

module parse failed : unexpected token

you may need an appropiate loader to handle this file type.

...

查了一下官方文档,发现v15做了一个比较大的升级,在使用vue-loader的时候,必须加一个VueLoaderPlugin,如下是解决方案。

// webpack.config.js

const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
  module: {
    rules: [
      // ... other rules
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      }
    ]
  },
  plugins: [
    // make sure to include the plugin!
    new VueLoaderPlugin()
  ]
}

当然如果想不想这么加,把vue-loader降到14.2.2就可以兼容旧的写法了。

参考文档: https://www.imooc.com/qadetail/251484

https://vue-loader.vuejs.org/guide/#manual-setup

扫码体验小程序版