Totty.js
Totty.js

Reputation: 15831

How to make node.js work without node_modules when bundled with webpack?

I want to deploy an app without having to bundle all the node_modules in the folder.

So instead of having this folder deployed:

To have something like:

In the binary_dependencies should only include the binaries that can't be included in the app.js file.

The reason is because yarn install will create a big layer (500MB) in docker and is slow to upload. I wanted to reduce that size.

Upvotes: 6

Views: 3863

Answers (2)

RudolphTheCat
RudolphTheCat

Reputation: 106

In my case, I did not have any "binary_dependencies" - all provided modules were bundled in "app.js". However, at first I had to disable webpack-node-externals as it purposely excluded some of the modules from my bundled "app.js". After disabling the module, I had to have only "Node" and app.js" on my docker container. By running "node app.js" I was able to start my "express.js" server without having to provide "node_modules" as they were already bundled inside my "app.js".

Upvotes: 1

mohammad mohammad
mohammad mohammad

Reputation: 394

upload the code with the file package.json, then cd to folder and run npm install Pay attention to the version you are installing suppose you have the following:

"dependencies": {
    "bluebird": "^3.5.1",
    "body-parser": "^1.18.3"
  }

change it to:

"dependencies": {
    "bluebird": "3.5.1",
    "body-parser": "1.18.3"
  }

Upvotes: 0

Related Questions