1

I'm building node/Express application and want to utilize 'latest and greatest':

node/Express + TypeScript + webpack.

Question: What are the benefits of using webpack to bundle all my nodejs code into one file? Just trying to understand if it is an overkill to use webpack for such purpose.

oKonyk
  • 1,468
  • 11
  • 16
  • Does this answer your question? [Webpack for back-end?](https://stackoverflow.com/questions/37788142/webpack-for-back-end) – bmaupin Jan 31 '22 at 16:11

2 Answers2

0

I think the biggest win you will get with Webpack would be Hot Module Replacement (HMR).

During development, if you were to use a tool like nodemon to watch for file changes you would have to wait for a full restart of your node application, whereas with Webpack HMR it will only update what is changed speeding up your development process. The upfront costs of setting up Webpack definitely payoff over the course of development.

Webpack also gives you the ability to use loaders. In your case using TypeScript you would likely want to use the ts-loader to transpile your code into standard javascript code that is compatible in your node environment.

pruhter
  • 517
  • 4
  • 6
0

Good that you're using the good combination of languages at the server-side. First of all understand why should we use Webpack. Webpack is used for module bundling by the builds we’re generating. As a best practice, we should not run the source directly.

Also, there two common modes available by default in webpack are,

  • Development
  • Production

Development build produces source map files and it’s not minified and uglified. It holds the information about the source files and even it is compressed and compiled it is easy to debug the development build. FYI, my development build file size is just ~51KB since I use mongoDB in my stack.

Production build compresses our source code into a minimized single file but performs the same task as source code does. It won’t produce source map files and it’s uglified and minified so the debugging is not possible. My prod build file size is just ~9KB.

Notice the size difference after the file compression from dev to prod.

So, I recommend to use webpack not only for bundling, also we can configure transpiler options using loaders in it.

Note: Webpack can be used for both Client and Server side.

Happy Coding!

Vivek K
  • 11
  • 4