Setting up a minimal Webpack 4 and Babel for NodeJS server

This is my basic setup to get started on a NodeJS server.
It uses Webpack 4 with Babel to take advantage of ES6 imports.

1. First initialize your app. In a new folder run:
$ npm init -y

2. Install your dependencies.

$ npm i -D babel-cli babel-preset-env nodemon

3. Create your .babel.rc with the following content

{
    "presets": [
        "env"
    ]
}

4. Include this start script in your package.json

"start": "nodemon main.js --exec babel-node --presets babel-preset-env"

5. Create a main.js and add a console.log

<code>console.log('Hello World!');</code>

That’s it!

Just npm start.

Author: mark

Creative technologist

Leave a Reply

Your email address will not be published. Required fields are marked *