Production build

This commit is contained in:
2023-03-12 07:43:40 +08:00
parent b492faedfa
commit 508eb82ff4
5 changed files with 58 additions and 4 deletions
+2 -1
View File
@@ -1 +1,2 @@
node_modules/*
node_modules/*
build/*
+10 -1
View File
@@ -13,15 +13,24 @@ WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
ENV NODE_ENV=$NODE_ENV
# install nginx
RUN apk update
RUN apk add nginx
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
COPY nginx.conf ./
COPY run.sh ./
RUN npm install
# add app
COPY . ./
# start app
CMD ["npm", "start"]
CMD /bin/sh ./run.sh
+29
View File
@@ -0,0 +1,29 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
gzip on;
listen 3000;
server_name localhost;
root /usr/src/app/build;
include /etc/nginx/mime.types;
location /nginx_status {
stub_status on;
access_log off;
}
location / {
try_files $uri $uri/ /index.html;
}
}
}
+2 -2
View File
@@ -18,8 +18,8 @@
"axios": "^0.24.0"
},
"scripts": {
"start": "react-scripts start -e .env",
"build": "react-scripts build -e .env",
"start": "react-scripts start -e .env.development",
"build": "react-scripts build -e .env.production",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Executable
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e
set -x
export NODE_ENV="${NODE_ENV:-development}"
if [ $NODE_ENV == "development" ]; then
# this runs webpack-dev-server with hot reloading
npm start
else
# build the app and serve it via nginx
npm run build
nginx -g 'daemon off;' -c /usr/src/app/nginx.conf
nginx -c /usr/src/app/nginx.conf
fi