
We’ve already seen more than enough to convince us about how useful Webpack is.
#Why use webpack and node js install#
Note: for the above code to work you will need to install the Babel loader, presets and Uglify plugin separately in your project using npm. We also specified dead_code: true which will remove all the dead code from the bundle which can be useful when setting up dynamic code branching and can also help reduce the size of the bundle. We set beautify: false so that the code of our generated bundle is not formatted, which makes it harder to read for malicious users. In the code above we declared uglifyJSPlugin object which is used to define settings for our plugin. Let’s take a look at a sample file, which is a configuration file used to declare all the plugins and loaders used by Webpack in your project: Thanks to Babel loader we can enjoy new JavaScript syntax and write our code using EcmaScript 2015 and even JSX (React). Plugins have much more control over the bundleīabel loader is used to convert code written in modern flavors and supersets of JavaScript into plain old JavaScript code supported by older browsers.Work at the end or after of bundle generation.Loaders work at the individual file level.

Work before or at the beginning of the bundle generation.While at first glance they might seem like they are used to accomplish same thing, loaders and plugins are different in Webpack: Built-in and third party loaders are one of the main reasons why Webpack is such a powerful and popular tool. Loaders and plugins in Webpack allow adding more rules or processing pipelines during the bundling process. One of the most prominent functionalities of the Webpack is plugins and loaders. However, Webpack is a very flexible and powerful tool that offers so much more. Since CommonsJS is arguably the best moduling system JavaScript world has to offer at the moment, this alone should be enough to start using Webpack. Wasn’t it easy to export and import modules using Node.js system? We didn’t have to worry about managing dependencies or configuring paths, all we had to do is export our greet module and import it using require. If you open our html page you should see the greeting. Image you have a project with two files greet.js and main.js. Let take a look at a quick example to get a better understanding:

We can write our application using Node.js moduling system and things like require() and module.exports and use Webpack to bundle it into a single JavaScript file that is compatible with all browsers.

Unfortunately, CommonJS is not natively supported by browsers. Node.js introduced a great solution – CommonJS moduling system. Before Node.js, developers had to use different kinds of tricks to avoid variable name collision in JavaScript. So what kind of processing are we talking about? To explain this we need to get back to the long-standing JavaScript problem of module collisions. Simply put, Webpack is a tool for putting your code through the processing pipeline and bundling it together into a single JavaScript file. So in this post I’m explaining Webpack in the simplest way possible. While it’s clear that Webpack plays a major part in the web development today, the exact features and functionalities of the Webpack weren’t clear to me until recently.

Ever since it’s release, it was adopted by major companies like Airbnb and Facebook, and web development frameworks like Angular and React. Webpack took web development world by storm.
