项目环境
node.js:v12.16.1
npm:v6.13.4
vue-cli:v4.2.3
本次安装的依赖有:
//package.json
"dependencies": {
"cross-env": "^7.0.2", cross-env可以用单个命令设置mode,而不必担心兼容不同的OS
"css-loader": "^3.4.2",
"file-loader": "^5.1.0", //url-loader依赖
"html-webpack-plugin": "^3.2.0", //用来在出口生成一个.html,才能访问网页
"style-loader": "^1.1.3",
"stylus": "^0.54.7", //stylus-loader依赖
"stylus-loader": "^3.0.2",
"url-loader": "^3.0.0",
"vue": "^2.6.11",
"vue-loader": "^15.9.0",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.42.0",
"webpack-dev-server": "^3.10.3" //使用webpack-dev-server可以实现热部署(动态监听文件的改变,并hot replace)
},
"devDependencies": {
//首先,它是dev的依赖,如果是用最新webpack原生构建,除了安装webpack外,还要安装webpck-cli,在webpack.config中配置mode选项
"webpack-cli": "^3.3.11"
}
试错过程
照着视频小心翼翼敲完,第一次运行npm run build
One CLI for webpack must be installed. These are recommended choices, delivered as separate pack
ages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no): yes
要我安装webpack-cli,安装后接着报错:)
第二次运行npm run build
Hash: 01c93cf3e20f7c7e5f8f
Version: webpack 4.42.0
Time: 2907ms
Built at: 2020-03-15 0:13:18
1 asset
Entrypoint main = bundle.js
[0] (webpack)/buildin/global.js 472 bytes {
0} [built]
[1] ./src/app.vue?vue&type=template&id=5ef48958&scoped=true& 263 bytes {
0} [built] [failed] [1 error]
[3] ./src/app.vue?vue&type=style&index=0&id=5ef48958&scoped=true&lang=css& 272 bytes {
0} [built] [failed] [1 error]
[7] ./s