Server-side Webpack configuration

Modify the code to require nodeExternals, and update the config object with the following in your webpack.config.server.js file to configure Webpack for bundling server-side code.

mern-simplesetup/webpack.config.server.js:

const config = {    name: "server",    entry: [ path.join(CURRENT_WORKING_DIR , './server/server.js') ],    target: "node",    output: {        path: path.join(CURRENT_WORKING_DIR , '/dist/'),        filename: "server.generated.js",        publicPath: '/dist/',        libraryTarget: "commonjs2"    },    externals: [nodeExternals()],    module: {        rules: [            {                test: /\.js$/,                exclude: /node_modules/,                use: [ 'babel-loader' ]            }        ]    }}

The mode option is not set here explicitly but will be passed as required when running the Webpack commands with ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.