You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在无GitHub仓库或已有项目仓库下创建Next.js 13前端应用

不依赖GitHub仓库创建Next.js应用的方法
  • 确保本地已安装**Node.js 18.17+**或更高版本(Next.js 13的最低要求)
  • 打开终端,执行对应命令创建项目:
    • npx方式:npx create-next-app@latest
    • yarn方式:yarn create next-app
    • pnpm方式:pnpm create next-app
  • 按终端引导完成配置:
    • 输入项目名称
    • 选择是否启用TypeScript
    • 选择是否启用ESLint
    • 选择是否集成Tailwind CSS
    • 选择是否使用src/目录
    • 选择是否采用App Router(Next.js 13默认推荐方案)
    • 选择是否自定义导入别名
  • 配置完成后,进入项目目录,执行启动命令:npm run dev(或yarn dev、pnpm dev)
  • 浏览器访问http://localhost:3000即可查看默认的Next.js页面
已有项目仓库搭建Next.js 13前端的实施步骤
  1. 进入项目根目录
    打开终端,通过cd命令进入你的已有项目文件夹

  2. 初始化package.json(若项目未存在)
    执行:npm init -y快速生成默认配置的package.json

  3. 安装核心依赖
    执行命令安装Next.js及关联依赖:npm install next@latest react@latest react-dom@latest

  4. 创建必要目录与文件

    • 在项目根目录新建app/文件夹(Next.js 13 App Router模式的核心目录)
    • 在app/目录下创建page.js(或page.tsx,若使用TypeScript)作为首页组件,示例代码:
      export default function Home() {
        return <h1>Hello, Next.js 13!</h1>;
      }
      
  5. 配置启动脚本
    在package.json的scripts字段中添加以下命令:

    "scripts": {
      "dev": "next dev",
      "build": "next build",
      "start": "next start",
      "lint": "next lint"
    }
    
  6. 启动开发服务器
    执行:npm run dev,访问http://localhost:3000即可看到你的Next.js前端页面

  7. 可选:自定义配置
    若需要调整Next.js行为,可在项目根目录创建next.config.js,示例配置:

    /** @type {import('next').NextConfig} */
    const nextConfig = {
      reactStrictMode: true,
    };
    
    module.exports = nextConfig;
    

内容的提问来源于stack exchange,提问作者jhahspu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 00:45:33