在webpack中使用配置文件
如果不想在终端中输入命令行,就可以创建一个可以取代CLI的配置文件
接上一篇文章webpack起步
- 在todo目录下新建文件并命名webpack.config.js
- 在webpack.config.js里编写以下内容
const path = require("path");
module.exports = {
entry:"./src/index.js",
output:{
filename:"bundle.js",
path:path.resolve(__dirname,"dist")
}
}
3.在终端执行npx webpack --config webpack.config.js
执行结果如下:
NPM脚本
如果不想用命令行(如:npx webpack --config webpack.config.js),可以设置一个快捷方式,在packge.json添加一个npm脚本(npm script)
packge.json
{
"name": "todo",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"build":"webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "4.40.2",
"webpack-cli": "3.3.9"
},
"dependencies": {
"lodash": "4.17.15"
}
}