webpack与Vue

2018-11-13  本文已影响0人  废柴阿W

安装Vue

npm i vue -S
import Vue from 'vue'

使用原方式的三种解决方法,解决方式:

使用.vue结尾的单文件组件

  1. 默认无法打包vue 需要安装相应loader: npm i vue-loader vue-template-compiler -D

2 webpack.config.js新增配置项{test:/\.vue$/, use: 'vue-loader'}

但是依旧错误,根据错误信息

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

在webpack.config.js中解决如下:

 const VueLoaderPlugin = require('vue-loader/lib/plugin');
 ...
 plugins: [
        // make sure to include the plugin for the magic
        new VueLoaderPlugin()
    ],

参考来源:https://blog.csdn.net/cominglately/article/details/80555210

3.注意:vue在webpack默认中只能使用render函数渲染组件

总结与梳理

export default 和 export的使用方式

Node中向外暴露成员的形式:

module.exports = {
}

在ES6中,也通过规范的形式,规定了如何导入和导出模块
在ES6中导入模块使用 import 模块名称 from ‘模块标识符’ 或 import ‘路径’
在ES6中,使用export default 和 export 向外暴露成员。

注意在ES6中:

Node中:

配置一个简单的vue项目时的webpack.config.js
上一篇 下一篇

猜你喜欢

热点阅读