Skip to content

Commit 6928083

Browse files
authored
Merge pull request #7076 from umbraco/v16/docs/umbraco-extension
CMS: Adds new article on `umbraco-extension`
2 parents 0d47061 + 336ba54 commit 6928083

File tree

6 files changed

+149
-23
lines changed

6 files changed

+149
-23
lines changed

16/umbraco-cms/.gitbook.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ redirects:
1010
fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor-tinymce/styles: fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/README.md
1111
fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor-tinymce/plugins: fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/extensions.md
1212
fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor-tinymce/blocks: fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/blocks.md
13-
fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/change-rich-text-editor-ui: fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/README.md
13+
fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/change-rich-text-editor-ui: fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/README.md
14+
customizing/development-flow/typescript-setup: customizing/development-flow/README.md

16/umbraco-cms/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@
142142
* [Extend and customize the editing experience](customizing/overview.md)
143143
* [Project Bellissima](customizing/project-bellissima.md)
144144
* [Setup Your Development Environment](customizing/development-flow/README.md)
145+
* [Umbraco Extension Template](customizing/development-flow/umbraco-extension-template.md)
145146
* [Vite Package Setup](customizing/development-flow/vite-package-setup.md)
146-
* [TypeScript setup](customizing/development-flow/typescript-setup.md)
147147
* [Extension Overview](customizing/extending-overview/README.md)
148148
* [Extension Registry](customizing/extending-overview/extension-registry/README.md)
149149
* [Extension Registration](customizing/extending-overview/extension-registry/extension-registry.md)

16/umbraco-cms/customizing/development-flow/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This article will take you through setting up everything you need to start build
99
## Required Software
1010

1111
Make sure you have followed the [requirements](../../fundamentals/setup/requirements.md) article, especially having installed the following on your machine:
12-
* [Node.js version 20.15.0 (LTS)](https://nodejs.org/en) and higher
12+
* [Node.js version 22.15.0 (Long-Term Support)](https://nodejs.org/en) and higher
1313

1414
{% hint style="info" %}
1515
Use Node Version Manager (NVM) for [Windows](https://github.com/coreybutler/nvm-windows) or [Mac/Linux](https://github.com/nvm-sh/nvm) to manage the Node.js versions.
@@ -21,6 +21,9 @@ Use Node Version Manager (NVM) for [Windows](https://github.com/coreybutler/nvm-
2121

2222
Extensions such as JavaScript, CSS, and manifests, will go into a folder called `App_Plugins`. If you do not have this folder, you can create it at the root of your Umbraco project.
2323

24+
{% hint style="info" %}
25+
You can include the `App_Plugins` folder in the `wwwroot` folder of a Razor Class Library (RCL) project, but it is not required.
26+
{% endhint %}
2427
### Source Code
2528

2629
The source code for your extensions should ideally be placed in a different project. You can make great use of a [Razor Class Library (RCL) with static assets](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-8.0\&tabs=visual-studio#create-an-rcl-with-static-assets) for this purpose. This will make it easier to maintain and test your code. You can create a new project in the root of your Umbraco project, or you can create a new project in a separate folder.
@@ -63,7 +66,7 @@ npm init -y
6366
Make sure that you do not install any NPM dependencies directly into the `App_Plugins` folder. This can cause issues with Build and Publish processes in MSBuild. Always install dependencies in a separate folder and use a bundler to copy the compiled files over to the `App_Plugins` folder.
6467
{% endhint %}
6568

66-
### Umbraco Backoffice
69+
### TypeScript Setup
6770

6871
Umbraco publishes an NPM package called `@umbraco-cms/backoffice` that holds typings and other niceties to build extensions.
6972

@@ -75,6 +78,25 @@ npm install -D @umbraco-cms/backoffice
7578

7679
This will add a package to your devDependencies containing the TypeScript definitions for the Umbraco Backoffice.
7780

81+
**TSConfig**
82+
83+
Make sure to configure your TypeScript compiler so it includes the Global Types from the Backoffice. This enables you to utilize the declared Extension Types. If your project is using other Packages that provide their Extension Types, list these as well.
84+
85+
In your `tsconfig.json` file, add the array `types` inside `compilerOptions`, with the entry of `@umbraco-cms/backoffice/extension-types`:
86+
87+
```json
88+
{
89+
"compilerOptions": {
90+
...
91+
"types": [
92+
"@umbraco-cms/backoffice/extension-types"
93+
]
94+
}
95+
}
96+
```
97+
98+
**Take extra care when using Vite**
99+
78100
It is important that this namespace is ignored in your bundler. If you are using Vite, you can add the following to your `vite.config.ts` file:
79101

80102
```ts
@@ -102,4 +124,4 @@ If you're using Visual Studio Code we recommend the extension called [Lit-Plugin
102124

103125
## What's Next?
104126

105-
Now that you have your development environment set up, you can start building your Umbraco extensions. Read more about [our recommended setup with Vite](vite-package-setup.md) to get started.
127+
Now that you have prepared your development environment, start building your Umbraco extensions. Read the article on [Umbraco Extension Template](./umbraco-extension-template.md) to set all this up.

16/umbraco-cms/customizing/development-flow/typescript-setup.md

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
description: Use the `umbraco-extension` .NET template to create a new Umbraco extension.
3+
---
4+
5+
# Umbraco Extension Template
6+
7+
Umbraco provides a .NET template to help you get started with building extensions for the Umbraco backoffice. This template sets up a new project with all the necessary files and configurations to build an extension. The template is called `umbraco-extension` and can be used to create a new Umbraco extension project with a single command.
8+
9+
## Prerequisites
10+
- [.NET SDK](https://dotnet.microsoft.com/download) version 9.0 or later
11+
- [Node.js](https://nodejs.org/en/download/) version 22 or later
12+
13+
## Install the Umbraco Extension Template
14+
To install the Umbraco extension template, run the following command in your terminal:
15+
16+
```bash
17+
dotnet new install Umbraco.Templates
18+
```
19+
20+
This command installs both the `umbraco` and `umbraco-extension` templates, which you can use to create new Umbraco and Umbraco extension projects. If a new Umbraco project has previously been created using `dotnet new umbraco`, the templates may already be installed.
21+
22+
## Create a New Umbraco Extension
23+
To create a new Umbraco extension project, run the following command in your terminal. It should be executed in a folder where you want to create the new project, for example in the root of your solution:
24+
25+
```bash
26+
dotnet new umbraco-extension -n MyExtension -ex
27+
```
28+
29+
This command creates a new folder called `MyExtension` with the following files and folders:
30+
- `MyExtension.csproj`: The project file for the extension.
31+
- `Constants.cs`: A file containing constants for the extension.
32+
- `Client`: A folder containing the source code for the extension, a `package.json` file, a `tsconfig.json` file, and the `vite.config.ts` configuration file.
33+
- `README.md`: A readme file with instructions on how to build and run the extension.
34+
35+
The `-ex` flag indicates that you want to include examples of how to use the extension. This flag is optional, but it is recommended to include it if you are new to building extensions for Umbraco. It will additionally give you:
36+
37+
- `Composers`: A folder containing an example composer that registers a custom Swagger API.
38+
- `Controllers`: A folder containing an example API controller for a dashboard.
39+
- `Client/src/api`: A folder containing an example API client that calls the API controller.
40+
- `Client/src/dashboards`: A folder containing an example dashboard Web Component that uses the API client.
41+
42+
After setup, the dashboard appears in the main **Content** section of the Backoffice.
43+
44+
### Add the Extension to an Umbraco Project
45+
46+
To include the extension in your Umbraco project, you need to add a reference to the extension project in your Umbraco project.
47+
48+
#### Option 1: Via Visual Studio
49+
50+
1. Right-click the **Dependencies** node in the Umbraco project.
51+
2. Select **Add Reference**.
52+
3. Choose the `MyExtension` project.
53+
4. Click **OK**.
54+
55+
#### Option 2: Via CLI
56+
Run the following command in the root folder of your Umbraco project:
57+
58+
```bash
59+
dotnet add reference ../MyExtension/MyExtension.csproj
60+
```
61+
62+
This command adds a reference to the `MyExtension` project in your Umbraco project. You can then build your Umbraco project and see the extension in action.
63+
64+
## Build and Run the Extension
65+
66+
To build and run the extension, install the dependencies and start the Vite development server. To do this, run the following commands in the `Client` folder of your extension project:
67+
68+
```bash
69+
npm install
70+
npm run build
71+
```
72+
73+
{% hint style="info" %}
74+
The project also builds automatically when running the Umbraco project. To start the Vite development server in watch mode, run the following command:
75+
76+
```bash
77+
npm run watch
78+
```
79+
{% endhint %}
80+
81+
This command compiles the TypeScript files and copies them over to the `wwwroot` output folder. Once complete, run the Umbraco project to view the extension in action.
82+
83+
## Publish the Project
84+
85+
The output files are automatically copied to the `wwwroot` folder of your Umbraco project. They are also included in the publishing process when you publish your Umbraco project. You can publish your Umbraco project using the following command:
86+
87+
```bash
88+
dotnet publish --configuration Release
89+
```
90+
91+
## Publish as a Package
92+
93+
To publish your extension as a package, create a NuGet package. Run the following command in the root folder of your extension project:
94+
95+
```bash
96+
dotnet pack --configuration Release
97+
```
98+
99+
This command creates a NuGet package in the `bin/Release` folder of your extension project. You can then publish this package to a NuGet feed or share it with others.
100+
101+
The `umbraco-extension` template is opinionated until a certain point. It is a starting point for building extensions for the Umbraco backoffice. The template includes a basic structure and configuration for building extensions, but you can customize it to fit your needs. You can add additional files, folders, and configurations as needed.
102+
103+
To publish your extension as an Umbraco Package, you need some additional files. For details, see the [Umbraco Package](../../customizing/umbraco-package.md) article.
104+
105+
### The Opinionated Starter Kit
106+
107+
Another option is to use the [Opinionated Umbraco Package Starter Template](https://github.com/LottePitcher/opinionated-package-starter). This is a template that includes all the files and configurations needed to build an Umbraco package. It builds on top of the `umbraco-extension` template and includes additional files and configurations for building Umbraco packages. This template is a great starting point for building Umbraco packages and includes everything you need to get started.
108+
109+
To install this template, run the following command in your terminal:
110+
111+
```bash
112+
dotnet new install Umbraco.Community.Templates.PackageStarter
113+
```
114+
115+
To create a new package project, run the following command:
116+
117+
```bash
118+
dotnet new umbracopackagestarter -n YourPackageName -an "Your Name" -gu "YourGitHubUsername" -gr "YourGitHubRepoName"
119+
```

16/umbraco-cms/customizing/development-flow/vite-package-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Get started with a Vite Package, setup with TypeScript and Lit
77
Umbraco recommends building extensions with a setup using TypeScript and a build tool such as Vite. Umbraco uses the library Lit for building web components which we will use throughout this guide.
88

99
{% hint style="info" %}
10-
These are general recommendations for working with and building extensions for the Umbraco backoffice. You can use any framework or library of your choice.
10+
These are general recommendations for working with and building extensions for the Umbraco backoffice. You can use any framework or library of your choice. For Umbraco's recommended approach, see the [Umbraco Extension Template](./umbraco-extension-template.md).
1111
{% endhint %}
1212

1313
## Before You Begin
@@ -127,7 +127,7 @@ npm run build
127127

128128
## Watch for changes and build
129129

130-
To continuously work on the package and have each change built, add a `watch`script in your `package.json` with `vite build --watch`.
130+
To continuously work on the package and have each change built, add a `watch`script in your `package.json` with `vite build --watch`.
131131

132132
The example below indicates where in the structure this change should be implemented:
133133

0 commit comments

Comments
 (0)