美文网首页
前端项目(React+Vue)docker部署

前端项目(React+Vue)docker部署

作者: Poppy11 | 来源:发表于2021-12-13 12:09 被阅读0次

dockerfile

FROM harbor.newegg.org/base/node:12-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install --registry=https://a.newegg.org/artifactory/api/npm/newegg-npm/
RUN npm run build
COPY . .

# production stage
FROM harbor.newegg.org/base/node:12-alpine  as production-stage
WORKDIR /app
RUN npm install express --registry=https://a.newegg.org/artifactory/api/npm/newegg-npm/ --save
COPY server.js  ./
COPY --from=build-stage /app/dist ./dist/
EXPOSE 8080
CMD ["node", "server.js"]

根目录创建server.js

const express = require('express');
const path = require('path')
const app = express();

app.use(express.static(path.join(__dirname, 'dist')));

app.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});

app.listen(8080, function () {
  console.log('http://localhost:8080/index.html');
});

相关文章

网友评论

      本文标题:前端项目(React+Vue)docker部署

      本文链接:https://www.haomeiwen.com/subject/luyjfrtx.html