跳到正文
Skillpedia
通用编程8.1k · #12616

webiny-project-structure

它能做什么

讲解 Webiny 项目的文件夹布局及其主配置文件的作用。适用于初次接触 Webiny、需要知道把代码放在哪里的开发者。

适用场景

  • ✓开发者询问自定义代码应放在 Webiny 项目的什么位置的时候。
  • ✓开发者想了解 webiny.config.tsx 文件作用的时候。
  • ✓开发者需要在 Webiny 项目中注册新扩展的时候。

技能链接

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/project-structure/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/webiny/webiny-js/blob/next/skills/user-skills/project-structure/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我应该把自定义代码放在 Webiny 项目的什么位置?”

每周 5 个新技能,1 分钟读完。

工作原理

该技能讲解主要文件夹和配置文件,所有扩展都在配置文件中注册。AI 利用这些信息将新代码放在正确的位置。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Webiny Project Structure

TL;DR

A Webiny project has a flat structure centered around webiny.config.tsx -- the single configuration file where all extensions are registered. Custom code lives in the extensions/ folder. Extensions are registered as React components (<Api.Extension>, <Admin.Extension>, <Infra.*>, <Cli.Command>) and can be conditionally loaded per environment.

Project Layout

my-webiny-project/
├── extensions/          # All custom code -- API, Admin, Infra, CLI extensions
│   └── README.md
├── public/              # Static assets for the Admin app
│   ├── favicon.ico
│   ├── global.css
│   ├── index.html
│   └── robots.txt
├── package.json         # Single package.json for the whole project
├── tsconfig.json        # Single TypeScript config
├── webiny.config.tsx    # Main configuration -- all extensions registered here
├── webiny-env.d.ts      # TypeScript environment types
└── yarn.lock

Key points:

  • Single package.json -- no monorepo, no workspaces needed.
  • Single tsconfig.json -- straightforward TypeScript setup.
  • webiny.config.tsx -- the entry point for everything. All extensions, infrastructure options, and project settings are declared here.
  • extensions/ -- where all your custom code lives. Organize with subfolders as needed (e.g., extensions/contactSubmission/, extensions/AdminBranding/).

The webiny.config.tsx File

This file exports a single React component called Extensions. It uses JSX to declaratively register all configuration:

// webiny.config.tsx
import React from "react";
import { Admin, Api, Cli, Infra, Project, Security } from "webiny/extensions";
import { Cognito } from "@webiny/cognito";

export const Extensions = () => {
  return (
    <>
      {/* Infrastructure configuration */}
      <Infra.Aws.DefaultRegion name={"us-east-1"} />
      <Infra.Core.OpenSearch enabled={true} />
      <Infra.Aws.Tags tags={{ OWNER: "me", PROJECT: "my-project" }} />

      {/* Identity provider */}
      <Cognito />

      {/* API extensions (backend) */}
      <Api.Extension src={"/extensions/ProductCategoryModel.ts"} />
      <Api.Extension src={"/extensions/ProductModel.ts"} />
      <Api.Extension src={"/extensions/contactSubmission/ContactSubmissionHook.ts"} />

      {/* Security hooks */}
      <Api.Extension src={"/extensions/MyApiKey.ts"} />
      <Security.ApiKey.AfterUpdate src={"/extensions/MyApiKeyAfterUpdate.ts"} />

      {/* Admin extensions (frontend) */}
      <Admin.Extension src={"/extensions/AdminTheme/AdminTheme.tsx"} />
      <Admin.Extension src={"/extensions/AdminTitleLogo/AdminTitleLogo.tsx"} />
      <Admin.Extension src={"/extensions/contactSubmission/EmailEntryListColumn.tsx"} />

      {/* Infrastructure / Pulumi extensions */}
      <Infra.Core.Pulumi src={"/extensions/MyCorePulumiHandler.ts"} />

      {/* CLI extensions */}
      <Cli.Command src={"/extensions/MyCustomCommand.ts"} />

      {/* Project settings */}
      <Project.Telemetry enabled={false} />
    </>
  );
};

Extension Types

JSX Element What It Does File Type
<Api.Extension src="..." /> Registers a backend extension (GraphQL schemas, content models, lifecycle hooks) .ts
<Admin.Extension src="..." /> Registers a frontend Admin UI extension (themes, branding, custom columns, custom forms) .tsx
<Infra.Core.Pulumi src="..." /> Registers a Pulumi infrastructure handler .ts
<Cli.Command src="..." /> Registers a custom CLI command .ts
<Security.ApiKey.AfterUpdate src="..." /> Registers a security lifecycle hook .ts

YOU MUST include the full file path with the .ts or .tsx extension in every src prop. For example, use src={"/extensions/MyModel.ts"}, NOT src={"/extensions/MyModel"}. Omitting the file extension will cause a build failure.

YOU MUST use export default for the createImplementation() call when the file is targeted directly by an Extensio

常见问题

extensions 文件夹是做什么的?

它存放用于 API、管理后台、基础设施和命令行部分的自定义代码。

Webiny 项目使用多个 package 文件吗?

不。该技能说明一个项目只有一个 package.json 和一个 tsconfig.json,不使用 monorepo 设置。

注册哪些类型的扩展?

该技能列出 API、管理后台、基础设施和命令行扩展,它们都作为组件添加到配置文件中。

详情

作者的原始描述

Webiny project layout, webiny.config.tsx anatomy, and extension registration. Use this skill when the developer asks about folder structure, where custom code goes, how to register extensions, what webiny.config.tsx does, or how the project is organized. Also use when they need to understand the relationship between extensions/, webiny.config.tsx, and the different extension types (Api, Admin, Infra, CLI).

repo: webiny/webiny-js

热度

GitHub 星标
8.1k
排名
#12616
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能