Using Webpack

Learn how to use Webpack and how to share a simple module between the browser and the server.

We'll cover the following

Now that we know how a module bundler works, let’s build a simple application that can work both on Node.js and on the browser.

Note: The code has been intentionally simplified just to illustrate how module bundlers work. There are many edge cases that we didn’t take into account. For instance, what happens if we require a module that doesn’t exist in the modules map?

Throughout this lesson, we’ll learn how to write a simple library that can be used without changes from the browser app and the server app. We’ll be using webpack to build the browser bundle.

To keep things simple, our application will be nothing more than a simple “hello world” for now.

Let’s start by installing the webpack CLI in our system with the following command:

Get hands-on with 1200+ tech skills courses.