Dockerized React App x Nodemon monitoring



我有一个在docker上运行的React应用程序,Nodemon检查App.js文件中的任何修改。我首先通过initial .bat初始化dockerfile,它只是构建。

initialise.bat

docker build . -f Dockerfile -t react-dev-app

DockerFile

FROM node:latest
WORKDIR /app
COPY package.json package-lock.json /app/
COPY public /app/public
COPY src /app/src
RUN npm install --verbose --only=production
COPY . .
RUN npm install --verbose -g nodemon
EXPOSE 3000
CMD ["nodemon", "--watch", "**/*", "App.js"]

docker-compose.yml

services:
devreact:
image: react-dev-app
stdin_open: true
tty: true
volumes:
- ./:/app
-  node_modules:/app/node_modules
ports: 
- "3000:3000"
volumes:
node_modules:

包。Json

{
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"nodemon": "^2.0.22",
"nth-check": "^2.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"css-select": "^4.1.3",
"nodemon": "^2.0.22"
}
}

react应用程序启动正常,但它没有检测到app .js或任何地方的任何更改。

我尝试更改包中的开始字符串。Json,但没有运气。还尝试了一个不同的包作为nodemon的替代品,仍然得到了相同的结果。在dockerfile中尝试了不同的CMD命令,仍然没有运气。我要么输入一个大循环,要么就是错误。

编辑Mac和pc之间似乎存在某种交叉兼容性问题。在Mac上,文件更改被监视,然后按预期重新启动,然后我在windows pc上访问文件,没有任何更改被监视。

在windows中你需要输入—legacy watch查看文件更改

version: '3'
services:
devreact:
build:
context: .
dockerfile: Dockerfile
stdin_open: true
tty: true
volumes:
- .:/app
- node_modules:/app/node_modules
ports:
- "3000:3000"
command: nodemon --legacy-watch App.js
volumes:
node_modules:

相关内容

  • 没有找到相关文章

最新更新