Reputation: 9219
I'm trying to figure out if webpack should be used at all on the backend of a node app (written in typescript), primarily because node has a built in module loader. I use tsc to convert the .ts files to .js and the module loader in node loads the files when running. What is the advantage on using webpack?
thanks
Upvotes: 3
Views: 2547
Reputation: 20424
Here are a few advantages of using a bundler like Webpack on the backend:
It allows you to bundle your app code into a single minified file that only contains the relevant code.
This is especially useful when you want to minimize the size of the package or want to create a standalone file that can be run without the node_modules directory.
It helps you cut down the app startup time by minimizing the bundle size and the time required for module lookup.
It makes it possible to have hot code loading on the server-side (can be done without webpack too)
It enables you to use other webpack plugins and loaders.
Considering all those advantages it has its own quirks and can make things more complicated than they should be. So obviously, only use it when it's absolutely necessary.
Upvotes: 4
Reputation: 1499
There is no hard and fast rule that you must use webpack
for bundling your node application .But, when you have the capability why not use it ,Webpack
is an awesome wholesome application bundler.The two main advantages using it are
Hot reload - keep watching for the specified changes and reloads on the go
Aliases - gives the managed path resolved based on array config in webpack
If you go through its documentation the best lines come into play that
It's a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS) and it can be extended to support many different assets such as images, fonts and stylesheets.
webpack cares about performance and load times; it's always improving or adding new features, such as async chunk loading and prefetching, to deliver the best possible experience for your project and your users.
Upvotes: 0