View profile

Do You Need Webpack for Server Side JavaScript?

There was an interesting question on Reddit about our basic introduction to Webpack configs:
Do You Need Webpack for Server Side JavaScript?
By Mastering JS Weekly • Issue #23 • View online
There was an interesting question on Reddit about our basic introduction to Webpack configs:

Worth taking a step back to think why you're using Webpack at all
Worth taking a step back to think why you're using Webpack at all
Do you really need Webpack for a server side JavaScript project? As is usually the case in software engineering, the answer is “it depends.” If you’re building a basic Express app that runs on Node.js, you don’t need Webpack at all. But here’s a few cases where you might:
  • Deploying a function to AWS Lambda. Lambda doesn’t let you install npm dependencies on their VMs. If you want to require() an npm module in AWS Lambda, you need to bundle first.
  • Using TypeScript. We don’t recommend using TS unless you’re working on a sophisticated Node.js library with several other developers - if you’re building a standard web app, you’re just wasting your time. But if you choose to use TS, Webpack’s watch functionality can save you a lot of time by automatically recompiling every time your code changes.
  • Server side rendering with specialized frontend syntax, like React’s JSX, or Vue’s single file components. If you’re trying to server-side render a frontend component that isn’t in JavaScript, you’ll need Webpack and plugins like vue-loader to compile the specialized syntax into JavaScript.
TLDR; if you’re writing vanilla JavaScript and not deploying to a serverless platform like Lambda, your Node.js project probably doesn’t need Webpack.
As a side note, we typically recommend avoiding specialized syntaxes like Vue’s single file components unless you have a good reason to. The more time you spend tinkering your Webpack config, the less time you have to build useful features and fix bugs.
Most Recent Tutorials
Did you enjoy this issue?
Mastering JS Weekly

A weekly summary of our tutorials

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue