javascript - How to resolve express server's dependencies after building to dist/ -
i use webpack bundle front end assets , put them in dist
directory. there express server serve index.html
html-webpack-plugin
generates , deposits in dist
. express server requires few node modules, express, body-parser, moment, etc.
there no node_modules
in dist
though however, falls @ first hurdle when express cannot found. should make separate package.json little express server , keep within dist
, , put npm install
on separate line of dockerfile (seems little complex...) or there better way server resolve dependencies after webpacking?
dockerfile
from node:8.4.0-alpine workdir /opt/app copy ./node_modules node_modules copy ./dist . expose 6500 entrypoint ["node", "server.js"]
line 5 is temporary attempt see if moving node_modules
app root allow server run. of course includes express , body-parser, react , webpack-dev-server.
you copying npm modules local system (most likely) alpine instance, different os not going compatible.
you need run run npm install
.
my guess need dockerfile similar this:
from node:8.4.0-alpine workdir /opt/app copy package.json . run npm install copy ./dist . expose 6500 //this might wrong: entrypoint ["node", "server.js"] cmd [ "npm", "start" ]
if understanding correctly might have move files afterwords:
run mv node_modules dist/node_modules
there nice tutorial might helpful here https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
Comments
Post a Comment