To use webpack with Node Express, we create a config that builds with 'node'
as its target.
For instance, in webpack.config.js, we write
module.exports = [
{
name: "server",
entry: "./src/server/index.js",
target: "node",
output: {
path: __dirname + "/dist/server",
filename: "bundle.js",
},
},
{
name: "client",
entry: "./src/client/index.js",
// target: 'web', // by default
output: {
path: __dirname + "/dist/client",
filename: "bundle.js",
},
},
];
to set the target
property to 'node'
in the first object to set the build target of the server app to Node.
We set the entry
property to the entry point file path.
And we set the output
property to an object with the bundle file path.