Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why use webpack with electron

Tags:

I am experimenting with electron. I see a lot of examples that use webpack.

But why use something like webpack? Because as far as I can tell electron supports require('module').

like image 987
Rutger Avatar asked Apr 14 '16 05:04

Rutger


People also ask

Is webpack necessary for electron?

It is not webpack which is used in electron. The require function is part of the node. js, which is the base for electron. But as long as webpack is also availiable as a node module (https://www.npmjs.com/package/webpack) it is also possible to use webpack with electron.

What are the benefits of using webpack?

Webpack gives you control over how to treat different assets it encounters. For example, you can decide to inline assets to your JavaScript bundles to avoid requests. Webpack also allows you to use techniques like CSS Modules to couple styling with components.

What is webpack What is the purpose of webpack?

Webpack is a static module bundler for JavaScript applications — it takes all the code from your application and makes it usable in a web browser. Modules are reusable chunks of code built from your app's JavaScript, node_modules, images, and the CSS styles which are packaged to be easily used in your website.

Why do we need webpack in Nodejs?

Webpack provides a great developer experience as it not only bundles JavaScript applications (supporting both EcmaScript Modules and CommonJS), but when paired with plugins and loaders it can be used for taking care of dependencies and assets, such as images, fonts, SASS, CSS, etx.


1 Answers

Webpack is not just a JS module bundler; it can be used for bundling static assets (inline base64 of images, for example), compiling Sass/Less/Stylus/CSS-Modules, dead code elimination, tree-shaking, and more. With the proper loaders and config, one only needs to require('any-type-of-file.extension') when actively developing. In my personal experience, however, more than all of that, Webpack is valuable because of it's dev-server and Hot Module Replacement (HMR), which makes Live Reload feel like something from the dark ages.

To recap, you get all the combined power of Gulp/Browserify/Rollup, but with HMR on top, all within a single tool (and lots and lots and lots and lots of loaders ;).

Setting up Webpack is a PITA, no doubt, but if you plan on working on an Electron app for a good amount of time, the time saved from HMR alone is well worth it.

like image 117
Lokua Avatar answered Sep 22 '22 02:09

Lokua