diff --git a/16/umbraco-cms/.gitbook.yaml b/16/umbraco-cms/.gitbook.yaml index af9f93527e9..5c9ea73f6fb 100644 --- a/16/umbraco-cms/.gitbook.yaml +++ b/16/umbraco-cms/.gitbook.yaml @@ -10,4 +10,5 @@ redirects: 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 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 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 - 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 \ No newline at end of file + 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 + customizing/development-flow/typescript-setup: customizing/development-flow/README.md diff --git a/16/umbraco-cms/SUMMARY.md b/16/umbraco-cms/SUMMARY.md index 6865bebeabb..4b67e4f3a66 100644 --- a/16/umbraco-cms/SUMMARY.md +++ b/16/umbraco-cms/SUMMARY.md @@ -142,8 +142,8 @@ * [Extend and customize the editing experience](customizing/overview.md) * [Project Bellissima](customizing/project-bellissima.md) * [Setup Your Development Environment](customizing/development-flow/README.md) + * [Umbraco Extension Template](customizing/development-flow/umbraco-extension-template.md) * [Vite Package Setup](customizing/development-flow/vite-package-setup.md) - * [TypeScript setup](customizing/development-flow/typescript-setup.md) * [Extension Overview](customizing/extending-overview/README.md) * [Extension Registry](customizing/extending-overview/extension-registry/README.md) * [Extension Registration](customizing/extending-overview/extension-registry/extension-registry.md) diff --git a/16/umbraco-cms/customizing/development-flow/README.md b/16/umbraco-cms/customizing/development-flow/README.md index 4a3df0dc1fe..216d6a0989d 100644 --- a/16/umbraco-cms/customizing/development-flow/README.md +++ b/16/umbraco-cms/customizing/development-flow/README.md @@ -9,7 +9,7 @@ This article will take you through setting up everything you need to start build ## Required Software Make sure you have followed the [requirements](../../fundamentals/setup/requirements.md) article, especially having installed the following on your machine: -* [Node.js version 20.15.0 (LTS)](https://nodejs.org/en) and higher +* [Node.js version 22.15.0 (Long-Term Support)](https://nodejs.org/en) and higher {% hint style="info" %} 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- 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. +{% hint style="info" %} +You can include the `App_Plugins` folder in the `wwwroot` folder of a Razor Class Library (RCL) project, but it is not required. +{% endhint %} ### Source Code 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 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. {% endhint %} -### Umbraco Backoffice +### TypeScript Setup Umbraco publishes an NPM package called `@umbraco-cms/backoffice` that holds typings and other niceties to build extensions. @@ -75,6 +78,25 @@ npm install -D @umbraco-cms/backoffice This will add a package to your devDependencies containing the TypeScript definitions for the Umbraco Backoffice. +**TSConfig** + +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. + +In your `tsconfig.json` file, add the array `types` inside `compilerOptions`, with the entry of `@umbraco-cms/backoffice/extension-types`: + +```json +{ + "compilerOptions": { + ... + "types": [ + "@umbraco-cms/backoffice/extension-types" + ] + } +} +``` + +**Take extra care when using Vite** + 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: ```ts @@ -102,4 +124,4 @@ If you're using Visual Studio Code we recommend the extension called [Lit-Plugin ## What's Next? -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. +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. diff --git a/16/umbraco-cms/customizing/development-flow/typescript-setup.md b/16/umbraco-cms/customizing/development-flow/typescript-setup.md deleted file mode 100644 index 3113b51d9bf..00000000000 --- a/16/umbraco-cms/customizing/development-flow/typescript-setup.md +++ /dev/null @@ -1,16 +0,0 @@ -# TypeScript setup - -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 provides their Extension Types then please list these as well. - -In your `tsconfig.json` file. Add the array `types` inside `compilerOptions`, with the entry of `@umbraco-cms/backoffice/extension-types`: - -```json -{ - "compilerOptions": { - ... - "types": [ - "@umbraco-cms/backoffice/extension-types" - ] - } -} -``` diff --git a/16/umbraco-cms/customizing/development-flow/umbraco-extension-template.md b/16/umbraco-cms/customizing/development-flow/umbraco-extension-template.md new file mode 100644 index 00000000000..1f32b8c0d37 --- /dev/null +++ b/16/umbraco-cms/customizing/development-flow/umbraco-extension-template.md @@ -0,0 +1,119 @@ +--- +description: Use the `umbraco-extension` .NET template to create a new Umbraco extension. +--- + +# Umbraco Extension Template + +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. + +## Prerequisites +- [.NET SDK](https://dotnet.microsoft.com/download) version 9.0 or later +- [Node.js](https://nodejs.org/en/download/) version 22 or later + +## Install the Umbraco Extension Template +To install the Umbraco extension template, run the following command in your terminal: + +```bash +dotnet new install Umbraco.Templates +``` + +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. + +## Create a New Umbraco Extension +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: + +```bash +dotnet new umbraco-extension -n MyExtension -ex +``` + +This command creates a new folder called `MyExtension` with the following files and folders: +- `MyExtension.csproj`: The project file for the extension. +- `Constants.cs`: A file containing constants for the extension. +- `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. +- `README.md`: A readme file with instructions on how to build and run the extension. + +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: + +- `Composers`: A folder containing an example composer that registers a custom Swagger API. +- `Controllers`: A folder containing an example API controller for a dashboard. +- `Client/src/api`: A folder containing an example API client that calls the API controller. +- `Client/src/dashboards`: A folder containing an example dashboard Web Component that uses the API client. + +After setup, the dashboard appears in the main **Content** section of the Backoffice. + +### Add the Extension to an Umbraco Project + +To include the extension in your Umbraco project, you need to add a reference to the extension project in your Umbraco project. + +#### Option 1: Via Visual Studio + +1. Right-click the **Dependencies** node in the Umbraco project. +2. Select **Add Reference**. +3. Choose the `MyExtension` project. +4. Click **OK**. + +#### Option 2: Via CLI +Run the following command in the root folder of your Umbraco project: + +```bash +dotnet add reference ../MyExtension/MyExtension.csproj +``` + +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. + +## Build and Run the Extension + +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: + +```bash +npm install +npm run build +``` + +{% hint style="info" %} +The project also builds automatically when running the Umbraco project. To start the Vite development server in watch mode, run the following command: + +```bash +npm run watch +``` +{% endhint %} + +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. + +## Publish the Project + +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: + +```bash +dotnet publish --configuration Release +``` + +## Publish as a Package + +To publish your extension as a package, create a NuGet package. Run the following command in the root folder of your extension project: + +```bash +dotnet pack --configuration Release +``` + +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. + +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. + +To publish your extension as an Umbraco Package, you need some additional files. For details, see the [Umbraco Package](../../customizing/umbraco-package.md) article. + +### The Opinionated Starter Kit + +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. + +To install this template, run the following command in your terminal: + +```bash +dotnet new install Umbraco.Community.Templates.PackageStarter +``` + +To create a new package project, run the following command: + +```bash +dotnet new umbracopackagestarter -n YourPackageName -an "Your Name" -gu "YourGitHubUsername" -gr "YourGitHubRepoName" +``` diff --git a/16/umbraco-cms/customizing/development-flow/vite-package-setup.md b/16/umbraco-cms/customizing/development-flow/vite-package-setup.md index fc27c3e8116..0afe7f7db7e 100644 --- a/16/umbraco-cms/customizing/development-flow/vite-package-setup.md +++ b/16/umbraco-cms/customizing/development-flow/vite-package-setup.md @@ -7,7 +7,7 @@ description: Get started with a Vite Package, setup with TypeScript and Lit 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. {% hint style="info" %} -These are general recommendations for working with and building extensions for the Umbraco backoffice. You can use any framework or library of your choice. +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). {% endhint %} ## Before You Begin @@ -127,7 +127,7 @@ npm run build ## Watch for changes and build -To continuously work on the package and have each change built, add a `watch`script in your `package.json` with `vite build --watch`. +To continuously work on the package and have each change built, add a `watch`script in your `package.json` with `vite build --watch`. The example below indicates where in the structure this change should be implemented: