Nx mono repo with NestJs & angularJs 不在容器中重新加载

Nx mono repo with NestJs & angularJs not reloading in container

我已经使用 angular 和 nestJS 应用程序创建了一个 NX monorepo,并非常努力地使重新加载在容器内工作,但无济于事。即使目录已正确挂载并且我验证了主机中的更改正在写入容器内,但不知何故进程没有接收它们。

我已经创建了一个独立的 nestJS 应用程序并成功地使其与容器一起工作。

Github 回购:https://github.com/navdbaloch/dockerized-development-with-nx-monorepo-angular-nestjs

ENV:windows10 与 WSL2,Docker 桌面 4.2.0

下面是docker-compose.xml文件

version: '3.7'

services:
  frontend:
    container_name: test-frontend
    hostname: poirot_frontend
    image: poirot_frontend
    build:
      context: .
      dockerfile: ./apps/fwa/Dockerfile.angular
      target: development
    ports:
      - 4200:4200
    networks:
      - poirot-network
    depends_on:
      - api
    volumes:
      - .:/usr/src
      - /usr/src/node_modules
    command: npm run start:app
  api:
    container_name: test-api
    hostname: poirot_api
    image: poirot_api
    build:
      context: .
      dockerfile: ./apps/fwa-api/Dockerfile.api
      target: development
    volumes:
      - .:/usr/src
      - /usr/src/node_modules
    ports:
      - 3333:3333
      - 9229:9229
    command: npm run start:api
    env_file:
      - .env
    networks:
      - poirot-network

networks:
  poirot-network:
    driver: bridge

Dockerfile.angular

FROM node:14-alpine As development

WORKDIR /usr/src
COPY package*.json ./
RUN  npm install minimist && \
    npm install --only=development

COPY . .
RUN npm run build:app

#! this is the production image
FROM nginx:latest as production
COPY ./docker/angular.conf /etc/nginx/nginx.conf
COPY --from=development /usr/src/dist/apps/fwa /usr/share/nginx/html

Dockerfile.api

FROM node:14-alpine As development

WORKDIR /usr/src

COPY package*.json ./

RUN  npm install minimist &&\
  npm install --only=development

COPY . .

RUN npm run build:api

#! this is the production image
FROM node:14-alpine as production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /app

COPY package*.json ./

RUN  npm install minimist typescript ts-node lodash reflect-metadata tslib rxjs @nestjs/platform-express @types/bcrypt && \
  npm install --only=production

COPY . .
COPY --from=development /usr/src/dist/apps/fwa-api ./dist
EXPOSE 3333
#! Migration runenr command: node_modules/ts-node/dist/bin.js migration-runner.ts
CMD ["node", "dist/main"]

经过反复试验,我终于成功了。

对于 angular 应用程序,已将服务器命令从 npx nx serve 更改为 npx nx serve --host 0.0.0.0 --poll 2000

对于 Api,在 angular.json 中添加 "poll": 2000 选项 projects.api.architect.build.options

我还更新了 Github repo 以供寻找相同解决方案的任何人参考。