Webpack creates a bundle of the code for a project. It compiles all our javascript files into a single file.
The code is gonna be written in the directory src and result in
a single file main.js in the dist directory.
npm init -y
npm install package-name
src directorysrcdist directory for distributionnpx webpack
main.js should be generated in distEach project can have a configuration file for webpack.
In the root of the project create webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
};
Run:
npx webpack –config webpack.config.js