我们将使用 dockersetup 开发一个 react pwa,并在部署到 master 分支期间将应用程序发布到 gitlab 页面上。
我在 Windows 设备上工作,无法在开发模式下获得热重载功能。每当我进行一些更改时,代码都不会重新编译。我必须docker-compose up --build
每次改变。
有没有办法让热重载在windows/docker/create-react-ap
p 设置上工作?
在 package.json 之后:
{
"name": "Appname",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"buildandserver": "react-scripts build && serve -s build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
现在是用于 Dev-Setup 的 Dockerfile:
FROM node:9.6.1
# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install react-scripts@1.1.1 -g
# start app
CMD ["npm", "start"]
至少是用于 dev-setup 的 docker-compose:
version: '3.5'
services:
App-Name:
container_name: App-Name
build:
context: .
dockerfile: devsetup/Dockerfile
volumes:
- './:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- '3000:3000'
environment:
- NODE_ENV=development
我在设备上运行 docker for windows。我希望任何人都可以帮助我离开这里...谢谢!