next js的两种部署方式 您所在的位置:网站首页 node部署方式 next js的两种部署方式

next js的两种部署方式

2023-07-04 03:58| 来源: 网络整理| 查看: 265

1.部署到nodejs服务器

执行build命令以后,生成的内容默认在.next文件夹里,

next build

然后你执行next start就能启动一个node js 服务

next start

也可以用docker部署

下面是官方提供的dockerfile 例子

# Install dependencies only when needed FROM node:alpine AS deps # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json yarn.lock ./ RUN yarn install --frozen-lockfile # Rebuild the source code only when needed FROM node:alpine AS builder WORKDIR /app COPY . . COPY --from=deps /app/node_modules ./node_modules RUN yarn build && yarn install --production --ignore-scripts --prefer-offline # Production image, copy all the files and run next FROM node:alpine AS runner WORKDIR /app ENV NODE_ENV production RUN addgroup -g 1001 -S nodejs RUN adduser -S nextjs -u 1001 # You only need to copy next.config.js if you are NOT using the default configuration # COPY --from=builder /app/next.config.js ./ COPY --from=builder /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json USER nextjs EXPOSE 3000 # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry # Uncomment the following line in case you want to disable telemetry. # ENV NEXT_TELEMETRY_DISABLED 1 CMD ["yarn", "start"] 2.导出静态HTML

执行下面这条命令

next build && next export

或者你也可以直接加入到package.json里,然后执行npm run build

"scripts": { "build": "next build && next export" }

默认生成的静态页面在out文件夹里.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有