需要为vue这种类型的文件声明一个loader

entry不要拼错了,entry用来设置入口文件路径

调用方法在package文件中配置建立好的webpack指令需要这样写才能调用我们自己建立后的webpack文件

output配置输出的路径filename是文件名path是输出的文件夹

entry是入口的配置将刚刚的入口文件打包

构建入口文件通过mount输出到html里

拼接绝对路径dirname是根目录路径


插件
vscode插件安装:


package.json里面项目的配置
npm init
npm i webpack vue vue-loader
npm i css-loader vue-template-compiler
插件
vue工程的搭建
npm init
1、npm i webpack vue vue-loader
2、npm i css-loader vue-template-compiler
3、新建src目录并在src下新建app.vue
4、在app.vue中编写vue组件
5、在根目录下新建webpack.config.js
Module build failed (from ./src/index.js):
C:\aboutHtml\pro_demo\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import Vue from 'vue'
^^^^^^
SyntaxError: Cannot use import statement outside a module
错误解决:
添加module :
module:{
rules:[
{
test: /.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /.vue$/,
loader: 'vue-loader'
}
]
},
导入模块:
npm install babel
npm install babel-core
npm install babel-loader@7.1.5
初始化项目npm init
安装需要的包npm install webpack Vue Vue-loader
安装需要的依赖 npm i css-loader vue-template-compiler
新建文件夹src 放置编码
.vue文件是vue的特殊开发方式;是一个组件不能直接挂载到html中

需要新建index.js文件
新建文件webpackconfig.js 打包前端资源
运行npm run build
报错信息
Module Error (from ./node_modules/vue-loader/lib/index.js):
vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin in your webpack config.
原因参考
https://vue-loader.vuejs.org/migrating.html#a-plugin-is-now-required
解决办法
// webpack.config.js
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
// ...
plugins: [
new VueLoaderPlugin()
]
}
根据vue-loader官方提供的15版本的声明方法,定义plugin。const VueLoaderPlugin = require('vue-loader/lib/plugin') module.exports = {
module: {
rules: [
// ... other rules
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new VueLoaderPlugin() //15版本需指定plugin
]}
npm i css-loader vue-template-compiler
npm i webpack vue vue-loader