setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Prepare a Remotion project for remocn

为 remocn 准备 Remotion 项目

Project root: $ARGUMENTS (the current folder when empty)
shadcn init
refuses a Remotion project ("could not detect a supported framework"), and Remotion's bundler doesn't read tsconfig paths. So a fresh project needs three small edits before the first component lands. Make them yourself with your file tools, in this order. Skip each one the project already has.
项目根目录:$ARGUMENTS(为空时为当前文件夹)
shadcn init
无法用于 Remotion 项目(“could not detect a supported framework”),并且 Remotion 的 bundler 不会读取 tsconfig paths。因此,新项目需要在第一个组件落地前完成三项小改动。请使用文件工具按以下顺序自行完成。项目已经具备的步骤则跳过。

0. Check the project

0. 检查项目

Read
package.json
in the project root.
  • No
    package.json
    : stop and say so.
  • No
    remotion
    in
    dependencies
    or
    devDependencies
    : it isn't a Remotion project. Stop and say so. The
    video
    skill creates one with
    npx create-video@latest --yes --blank <folder>
    .
In a project the user already had, list the files from the steps below that you will touch and ask before editing them.
读取项目根目录中的
package.json
。
  • 不存在
    package.json
    :停止操作并告知用户。
  • dependencies
    或
    devDependencies
    中没有
    remotion
    :这不是 Remotion 项目。停止操作并告知用户。
    video
    skill 可以使用
    npx create-video@latest --yes --blank <folder>
    创建一个项目。
对于用户原本已有的项目,请列出后续步骤中将要修改的文件,并在编辑前征得用户同意。

1.
components.json

1.
components.json

  • Missing: create it with exactly this content:
    json
    {
      "$schema": "https://ui.shadcn.com/schema.json",
      "style": "new-york",
      "rsc": false,
      "tsx": true,
      "tailwind": { "config": "", "css": "", "baseColor": "neutral", "cssVariables": false },
      "aliases": {
        "components": "@/components",
        "utils": "@/lib/utils",
        "ui": "@/components/ui",
        "lib": "@/lib",
        "hooks": "@/hooks"
      },
      "registries": { "@remocn": "https://remocn.dev/r/{name}.json" }
    }
  • Present, no
    registries["@remocn"]
    :
    add
    "@remocn": "https://remocn.dev/r/{name}.json"
    to
    registries
    , creating the object if needed. Leave every other field as it is.
  • Already has
    @remocn
    :
    leave it.
  • 不存在: 使用以下完全相同的内容创建它:
    json
    {
      "$schema": "https://ui.shadcn.com/schema.json",
      "style": "new-york",
      "rsc": false,
      "tsx": true,
      "tailwind": { "config": "", "css": "", "baseColor": "neutral", "cssVariables": false },
      "aliases": {
        "components": "@/components",
        "utils": "@/lib/utils",
        "ui": "@/components/ui",
        "lib": "@/lib",
        "hooks": "@/hooks"
      },
      "registries": { "@remocn": "https://remocn.dev/r/{name}.json" }
    }
  • 已存在,但不存在
    registries["@remocn"]
    :
    将
    "@remocn": "https://remocn.dev/r/{name}.json"
    添加到
    registries
    ,必要时创建该对象。其他所有字段保持不变。
  • 已经包含
    @remocn
    :
    保持不变。

2. The
@/*
path in
tsconfig.json

2.
tsconfig.json
中的
@/*
path

remocn components import each other through
@/
, so TypeScript has to resolve it.
tsconfig.json
may hold comments and trailing commas: edit it in place and keep them.
Work out the alias folder, the folder
@/
points at, relative to the project root. You need it in step 3.
  • compilerOptions.paths["@/*"]
    exists:
    leave the file. The alias folder is its first entry without the trailing
    /*
    (
    ./src/*
    →
    src
    ), resolved against
    compilerOptions.baseUrl
    when one is set, else against the folder of
    tsconfig.json
    .
  • The file has
    extends
    and no
    paths
    of its own:
    a local
    paths
    would replace the inherited map, not merge with it. Open the config it extends (one level, relative paths only). If that one has
    @/*
    , leave both files and take the alias folder from there, resolved against the parent's folder. If it doesn't, don't edit: tell the user to add
    "@/*": ["./src/*"]
    where their paths are defined, and use
    src
    as the alias folder.
  • Otherwise: add
    "@/*": ["./src/*"]
    to
    compilerOptions.paths
    , creating
    paths
    if needed and keeping existing entries. With a
    baseUrl
    other than
    .
    , write the path to
    src
    relative to the
    baseUrl
    instead. The alias folder is
    src
    .
  • No
    tsconfig.json
    :
    don't create one. The alias folder is
    src
    .
remocn 组件通过
@/
相互 import,因此 TypeScript 必须能够解析它。
tsconfig.json
中可能包含注释和尾随逗号:请原地编辑并保留它们。
确定 alias 文件夹,即相对于项目根目录、
@/
指向的文件夹。步骤 3 需要使用它。
  • compilerOptions.paths["@/*"]
    已存在:
    保持文件不变。alias 文件夹是其第一个条目去掉末尾
    /*
    后的结果(
    ./src/*
    →
    src
    );如果设置了
    compilerOptions.baseUrl
    ,则相对于该
    baseUrl
    解析,否则相对于
    tsconfig.json
    所在文件夹解析。
  • 文件包含
    extends
    ,但没有自己的
    paths
    :
    本地
    paths
    会替换继承的映射,而不是与其合并。打开它继承的配置(仅处理一层,且仅限相对路径)。如果该配置包含
    @/*
    ,则两个文件都保持不变,并从其中获取 alias 文件夹,相对于父配置的文件夹解析。如果没有,则不要编辑:告知用户,应在其定义 paths 的位置添加
    "@/*": ["./src/*"]
    ,并将
    src
    作为 alias 文件夹。
  • 其他情况: 将
    "@/*": ["./src/*"]
    添加到
    compilerOptions.paths
    ,必要时创建
    paths
    ,并保留现有条目。如果
    baseUrl
    不是
    .
    ,则写入相对于
    baseUrl
    指向
    src
    的路径。alias 文件夹为
    src
    。
  • 不存在
    tsconfig.json
    :
    不要创建。alias 文件夹为
    src
    。

3. The
@
alias in
remotion.config.ts

3.
remotion.config.ts
中的
@
alias

The bundler needs the same alias. Look for
remotion.config.ts
, then
remotion.config.js
, in the project root. If the file already contains
withRemocnAlias
, leave it.
The alias target is
path.join(process.cwd(), "<alias folder>")
, or
process.cwd()
when the alias folder is the project root itself.
  • No config file: create
    remotion.config.ts
    with the imports and the block below.
  • remotion.config.ts
    exists:
    add
    import path from "node:path";
    and
    import { Config } from "@remotion/cli/config";
    at the top unless they're already imported, then append the block at the end of the file.
  • remotion.config.js
    exists:
    append the same block without the type annotations (
    const withRemocnAlias = (config) => ({ ... })
    and
    config.resolve?.alias ?? {}
    ), and the same two imports if missing.
ts
// remocn components import each other through the "@/" alias in components.json.
// Bundlers don't read tsconfig paths, so the alias is resolved here as well.
// Both overrides are deliberate: the Remotion CLI applies overrideBundlerConfig
// with webpack and rspack alike, while Remocn Studio's preview reads only
// overrideWebpackConfig. Both run from the project root, which process.cwd()
// points at.
const withRemocnAlias = <C extends { resolve?: object }>(config: C): C => ({
  ...config,
  resolve: {
    ...config.resolve,
    alias: {
      ...((config.resolve as { alias?: object } | undefined)?.alias ?? {}),
      "@": path.join(process.cwd(), "src"),
    },
  },
});
// overrideBundlerConfig only exists in newer Remotion 4 releases.
if (typeof Config.overrideBundlerConfig === "function") {
  Config.overrideBundlerConfig(withRemocnAlias);
}
Config.overrideWebpackConfig(withRemocnAlias);
Replace
path.join(process.cwd(), "src")
with the alias target from above when they differ.
bundler 需要相同的 alias。在项目根目录中先查找
remotion.config.ts
,然后查找
remotion.config.js
。如果文件已经包含
withRemocnAlias
,则保持不变。
alias 目标为
path.join(process.cwd(), "<alias folder>")
;如果 alias 文件夹就是项目根目录,则目标为
process.cwd()
。
  • 不存在配置文件: 使用以下 imports 和代码块创建
    remotion.config.ts
    。
  • remotion.config.ts
    已存在:
    除非已经 import,否则在文件顶部添加
    import path from "node:path";
    和
    import { Config } from "@remotion/cli/config";
    ,然后将代码块追加到文件末尾。
  • remotion.config.js
    已存在:
    追加相同的代码块,但不带类型标注(
    const withRemocnAlias = (config) => ({ ... })
    和
    config.resolve?.alias ?? {}
    ),并在缺少时添加上述两个 imports。
ts
// remocn components import each other through the "@/" alias in components.json.
// Bundlers don't read tsconfig paths, so the alias is resolved here as well.
// Both overrides are deliberate: the Remotion CLI applies overrideBundlerConfig
// with webpack and rspack alike, while Remocn Studio's preview reads only
// overrideWebpackConfig. Both run from the project root, which process.cwd()
// points at.
const withRemocnAlias = <C extends { resolve?: object }>(config: C): C => ({
  ...config,
  resolve: {
    ...config.resolve,
    alias: {
      ...((config.resolve as { alias?: object } | undefined)?.alias ?? {}),
      "@": path.join(process.cwd(), "src"),
    },
  },
});
// overrideBundlerConfig only exists in newer Remotion 4 releases.
if (typeof Config.overrideBundlerConfig === "function") {
  Config.overrideBundlerConfig(withRemocnAlias);
}
Config.overrideWebpackConfig(withRemocnAlias);
当上述 alias 目标不同时,将
path.join(process.cwd(), "src")
替换为对应的 alias 目标。

4. Report

4. 报告

Tell the user, in a few lines, what each step did: created, changed or left as it was, plus anything they have to add by hand. Then
npx shadcn@latest add @remocn/<name>
works in the project.
用几行向用户说明每个步骤做了什么:创建、修改或保持不变的内容,以及用户必须手动添加的任何内容。之后,
npx shadcn@latest add @remocn/<name>
即可在该项目中运行。