Vue Vue-loader / VueLoaderPlugin / Webpack

在不用VueCli创建项目的时候,手写引入vue的时候,配置webpack的时候发现了这个问题

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

这是因为在15.x.x版本之后,如果要使用vue-loader,需要在webpack种使用vue-loader自带的插件,修改webpack.config.js的内容,如下图红色标记

const path = require('path') // node内置模块
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const config = {
  mode: 'none',
  entry: './src/main',
  output: {
    filename: 'bundle.js',
  },
  module: {
    rules: [
      //....
      {
        test: /\.vue$/,
        use: ['vue-loader']
      }
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Webpack Plugin Sample',
      template: './src/index.html'
    }),
    new VueLoaderPlugin()
  ]
}
module.exports = config