本文开始讲解如何通过webpack配置文件打包,首先,来看一下项目的目录结构。
上一篇文章讲到最基础的打包方式,没有使用webpack的配置文件来打包。使用webpack配置文件就得先在目录中新建一个webpack.config.js文件,这个就是webpack的配置文件。
1、新建webpack.config.js文件
touch webpack.config.js
2、目录
3、在配置文件中编写入口文件、输出打包文件的位置
const path = require('path');
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
}
4、查看index.html文件,因为之前写了引入打包文件的路径是.