Before we can begin bundling our web sites/applications using webpack, we need to install Node.js due to its role as a runtime environment for JavaScript. It also provides the Node Package Manager (npm), a powerful tool for managing project dependencies and installing third-party packages, which is crucial for building applications that leverage various libraries and modules.
To install Node.js on your system, follow these steps:
node -v
This command will display the installed Node.js version. Additionally, you can run npm -v
to check the version of npm (Node Package Manager) installed.
<aside> 💡 I will be using pnpm throughout this entire tutorial. However you can choose any package manager of your choice.
</aside>
To create the package.json
file, we can use a package manager such as npm
or pnpm
and run the init
command. Once we have answered a few questions about our project, the package manager will generate a package.json
file for us.
Let's start by creating a package.json
file using pnpm
.
mkdir webpack-mastery
cd webpack-mastery
pnpm init
Now we will install webpack. webpack is a powerful tool that allows us to bundle our code and manage dependencies efficiently. By using webpack, we can create a more organized and optimized development environment. Once we have installed webpack, we can start writing our configuration files.
These configuration files will define how our application is built and compiled. We can specify which files to include, how they are processed, and how they are output. With webpack, we have the flexibility to customize our build process to meet our specific needs. So, let's get started by installing webpack!
pnpm add -D webpack webpack-cli
This command will add webpack and webpack-cli as development dependencies in your project. The -D
flag indicates that these packages should be installed as devDependencies, which are only required during the development process.