Run webpack build during docker-compose build process
Please use
RUN bash -l -c 'npm run build-production'
instead of your
RUN npm run build-production # <<< Fails here
this should help
The problem could be that build-production
requires a devDependencies
, which are not being installed.
A great way to keep your production images small is to use a tool like dobi. It makes it easy to run the build tasks in a dev container, then pack everything into a production image, all with a single command.
Below is an example dobi.yaml
that might work for you.
meta: project: some-project-nameimage=builder: image: myproject-dev context: dockerfiles/ dockerfile: Dockerfile.buildimage=production: image: user/prod-image-name context: . depends: [build]mount=source: bind: . path: /coderun=build: use: builder mounts: [source] command: "npm run build-production" artifact: path/to/minified/assets
Running dobi production
will run any of the tasks that are stale. If none of the source files have changed the tasks are skipped. The depends: [build]
ensures that the build step always runs first.