© Mohamed Bouzid 2020
M. BouzidWebpack for Beginnershttps://doi.org/10.1007/978-1-4842-5896-5_2

2. Write Modular Code

Mohamed Bouzid1 
(1)
NA, Morocco
 

We have seen how to install webpack and use it in order to bundle our index.js file. Now it’s time to see how to add more code files (like in most real-world applications) and let webpack combine them into one file. Then we will learn how to customize our own configuration instead of relying on the default configuration provided by webpack.

Separate in Multiple Files

As we already saw, we used webpack to bundle our JavaScript. However, in our example, we used one JavaScript file only. What about multiple (two, three, or more) files?

Calling a Function from an External File

Let’s add a new JavaScript file ...

Get Webpack for Beginners: Your Step-by-Step Guide to Learning Webpack 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.