2

我已经安装了 react-snap 并希望它为我的页面编制索引,以便它们可用于 SEO;我已根据以下 dockerfile 与 docker 集成。但是,每当我进行 docker build 时,它都会显示“从 1 中抓取 1 (/)”,所以我认为它不会占用我的整个站点。有谁知道如何解决?

Docker 文件是:

ARG NODE_VERSION=lts

# Dependencies
FROM node:${NODE_VERSION}-slim as dependencies
WORKDIR /home/node/

RUN apt-get update
RUN apt-get install -y build-essential python
RUN npm install --global npm node-gyp

COPY package.json *package-lock.json *.npmrc ./

ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}
RUN npm ci

# Application
FROM node:${NODE_VERSION}-slim as build
WORKDIR /home/node/

COPY --from=dependencies /home/node/node_modules node_modules
COPY . .

ENV PATH="$PATH:/home/node/node_modules/.bin"
ENV NODE_ENV production

###
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    --no-install-recommends
# Install Google Chrome
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
    apt-get -yqq update && \
    apt-get -yqq install google-chrome-stable && \
    rm -rf /var/lib/apt/lists/*

RUN npm run build

# Nginx
FROM nginx:1.16

COPY --from=build /home/node/build /var/www
COPY conf.nginx /etc/nginx/conf.d/default.conf

我也有 package.json:

{
  "name": "myapp_web_ui",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@bugsnag/js": "^6.4.3",
    "@bugsnag/plugin-react": "^6.4.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.19",
    "@fortawesome/free-brands-svg-icons": "^5.9.0",
    "@fortawesome/free-regular-svg-icons": "^5.9.0",
    "@fortawesome/free-solid-svg-icons": "^5.9.0",
    "@fortawesome/react-fontawesome": "^0.1.4",
    "animate.css": "^3.7.2",
    "apexcharts": "^3.10.0",
    "firebase": "^6.3.0",
    "js-cookie": "^2.2.1",
    "jsqr": "^1.2.0",
    "lato-font": "^3.0.0",
    "lodash": "^4.17.14",
    "moment": "^2.24.0",
    "node-sass": "^4.12.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-apexcharts": "^1.3.3",
    "react-bootstrap": "^1.0.0-beta.9",
    "react-bootstrap-timezone-picker": "^2.0.0",
    "react-datetime": "^2.16.3",
    "react-dom": "^16.8.6",
    "react-modal": "^3.8.1",
    "react-places-autocomplete": "^7.2.1",
    "react-redux": "^7.0.2",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.2.0",
    "react-snap": "^1.23.0",
    "react-stripe-elements": "^4.0.0",
    "react-tooltip": "^3.10.0",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "typeface-montserrat": "0.0.75",
    "whatwg-fetch": "^3.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint src",
    "serve:prod": "serve -s build -l 4000",
    "postbuild": "react-snap",
    "snap": "react-snap"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "reactSnap": {
     "puppeteerArgs": [
       "--no-sandbox",
       "--disable-setuid-sandbox"
     ]
   },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "serve": "^11.2.0"
  }
}
4

1 回答 1

0

需要提前定义好要爬取的路由;

// in package.json

"reactSnap": {
    "include": ["/", "/login", "/contact", "/about", ...]
}

默认情况下,它只包含"/",因此它只抓取该路由并结束该过程。

于 2021-04-17T19:16:13.933 回答