webpack: eject nodejs server bundle with needed externals into stand alone dir

108 Views Asked by At

My higher goal is to create a .zip file with the server bundle and all needed assets. That file can be then moved to another device and executed there (the other device has the same NodeJS version installed). Building this on the device is not an option, because it's offline.

build/
|- node_modules //this is where I would like to have my externals
|- server.bundle.js
|- public/

My current solution is to pick and copy the external modules by hand, which is neither scalable nor convenient.

Would there be a possiblity, to let webpack handle this for me? Or even bundling externals like express into the bundle itself.

1

There are 1 best solutions below

0
On BEST ANSWER

You could have just express in the dependencyarray on package.json, then run npm install --productionto just install that, so your node_modules is going to be small.

In the webpack config, you have to be sure to add externals (webpack_externals). Due to some binaries in some node dependencies, webpack is not able to bundle them together. You are going to have a require call for just those dependencies.