> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Migrate a Custom Element Extension

## Article: Migrate a Custom Element Extension

## Article Link: https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/migrate-an-app-to-the-new-cli/migrate-an-app-from-the-legacy-cli/migrate-a-custom-element-extension.md

## Article Content:

# Migrate a Custom Element Extension

Add a custom element extension to your new Wix CLI project as part of [migrating an app from the legacy Wix CLI](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/migrate-an-app-to-the-new-cli/migrate-an-app-from-the-legacy-cli/migrate-a-legacy-cli-app-to-the-new-wix-cli.md).

## Folder structure

| Legacy path | New path |
|--------|-----|
| `src/site/widgets/custom-elements/<name>/element.json` | `src/extensions/site/widgets/<name>/<name>.extension.ts` |
| `src/site/widgets/custom-elements/<name>/element.tsx` | `src/extensions/site/widgets/<name>/<name>.tsx` |
| `src/site/widgets/custom-elements/<name>/panel.tsx` | `src/extensions/site/widgets/<name>/<name>.panel.tsx` |
| `src/site/widgets/custom-elements/<name>/element.module.css` | `src/extensions/site/widgets/<name>/<name>.module.css` |

> **Note:** `<name>` is your extension's folder name in the legacy project. The new folder and files use the same name.

## Step 1 | Copy and rename the files

In the new project:

1. Create the folder `src/extensions/site/widgets/<name>/`.
2. From the legacy project's `src/site/widgets/custom-elements/<name>/` folder, copy the following files into the new folder, and rename them:
    - `element.tsx` to `<name>.tsx`
    - `panel.tsx`, if present, to `<name>.panel.tsx`
    - `element.module.css`, if present, to `<name>.module.css`

Don't copy the legacy `element.json` file. You recreate its values in `<name>.extension.ts`.

## Step 2 | Adapt the code to the new project

In `<name>.tsx` and `<name>.panel.tsx`:

1. Update any imports as needed, to use the new paths.
2. If either file calls a web method or an HTTP function, replace the call. Fixing the import path isn't enough, because the legacy backend code doesn't exist in that form after the migration. See [Migrate from Web Methods to HTTP Endpoints](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/migrate-an-app-to-the-new-cli/migrate-an-app-from-the-legacy-cli/migrate-from-web-methods-to-http-endpoints.md#update-your-frontend-call-sites-as-you-migrate-each-extension) or [Migrate from HTTP Functions to HTTP Endpoints](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/migrate-an-app-to-the-new-cli/migrate-an-app-from-the-legacy-cli/migrate-from-http-functions-to-http-endpoints.md#update-your-frontend-call-sites-as-you-migrate-each-extension).

## Step 3 | Create the extension file

In the new project:

1. In `src/extensions/site/widgets/<name>/`, create `<name>.extension.ts`.
2. Add the following code, and set each field to the value the table below specifies:

    ```ts
    import { extensions } from '@wix/custom-extensions';

    export default extensions.customElement({
      id: '<value>',
      name: '<value>',
      width: {
        defaultWidth: <value>,
      },
      height: {
        defaultHeight: <value>,
      },
      installation: {
        autoAdd: <value>,
      },
      tagName: '<name>',
      element: './extensions/site/widgets/<name>/<name>.tsx',
    });
    ```

    | Field | Source in legacy project | What to specify |
    |-------|--------------------------|-----------------|
    | `id` | `id` in `element.json` | Copy source as is |
    | `name` | `name` in `element.json` | Copy source as is |
    | `width` | `width` in `element.json` | Copy source as is, including `allowStretch` and `stretchByDefault` if your legacy config sets them. Only `defaultWidth` is required. |
    | `height` | `height` in `element.json` | Copy source as is |
    | `installation.autoAdd` | `installation.autoAddToSite` in `element.json` | Copy source as is, or `false` if the legacy config doesn't set it |
    | `tagName` | None | The extension folder name |
    | `element` | None | Path to `<name>.tsx`, relative to `src/` |

3. Add any of the following fields that apply, inside the same object. Add `essential` to the existing `installation` object, not as a second `installation` field:

    ```ts
    installation: {
      autoAdd: <value>,
      essential: <value>,
    },
    presets: [
      {
        id: '<value>',
        name: '<value>',
        thumbnailUrl: '<value>',
      },
    ],
    behaviors: <value>,
    settings: './extensions/site/widgets/<name>/<name>.panel.tsx',
    ```

    | Field | Source in legacy project | What to specify | Condition |
    |-------|--------------------------|-----------------|-----------|
    | `installation.essential` | `installation.essential` in `element.json` | Copy source as is | Only if your legacy `element.json` sets it |
    | `presets` | `presets` in `element.json` | Copy the preset's `id` and `thumbnailUrl`, and add a `name`, which legacy presets don't have. Use the element's `name`, which is the preset name the legacy CLI writes to the app manifest. If the `thumbnailUrl` references a local `assets/` folder, see [Update the preset thumbnail URL](#update-the-preset-thumbnail-url). | Only if your legacy `element.json` sets it |
    | `behaviors` | `behaviors` in `element.json`, such as the dashboard page the widget links to | Copy source as is | Only if your legacy `element.json` sets it |
    | `settings` | None | Path to `<name>.panel.tsx`, relative to `src/` | Only if the legacy extension has a `panel.tsx` file |

<blockquote class="important">

__Important:__
The `id` must match the value from the legacy `element.json`. Otherwise, the new entry is treated as a separate extension instead of a continuation of the legacy one.

</blockquote>

### Update the preset thumbnail URL

A legacy custom element has at most 1 preset. If its `thumbnailUrl` references a local `assets/` folder, replace the value with `{{BASE_URL}}/thumbnail.png`:

```ts
presets: [
  {
    id: '<value>',
    name: '<value>',
    thumbnailUrl: '{{BASE_URL}}/thumbnail.png',
  },
],
```

Move the image itself into the new project's `public/` folder, which is where `{{BASE_URL}}` resolves to.

## Step 4 | Register the extension

In the new project, in `src/extensions.ts`:

1. Import the extension:

    ```ts
    import myCustomElement from './extensions/site/widgets/<name>/<name>.extension';
    ```

2. Add a `.use()` call for it to the `app()` chain, on its own line:

    ```ts
    .use(myCustomElement)
    ```

## Step 5 | Return to the main migration guide

Return to [Install the extension's dependencies](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/migrate-an-app-to-the-new-cli/migrate-an-app-from-the-legacy-cli/migrate-a-legacy-cli-app-to-the-new-wix-cli.md#install-the-extensions-dependencies) in the main migration guide.