You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 15/umbraco-cms/customizing/development-flow/vite-package-setup.md
+41-47
Original file line number
Diff line number
Diff line change
@@ -7,73 +7,69 @@ description: Get started with a Vite Package, setup with TypeScript and Lit
7
7
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.
8
8
9
9
{% hint style="info" %}
10
-
This guide is based on our **general recommendations** for working with and building extensions for the Umbraco backoffice.
11
-
12
-
You can use **any framework or library**, as you are not limited to the mentioned frameworks.
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.
13
11
{% endhint %}
14
12
15
-
## Getting Started With Vite
13
+
## Before You Begin
16
14
17
-
Vite comes with a set of good presets to get you quickly up and running with libraries and languages. For example: Lit, Svelte, and Vanilla Web Components with both JavaScript and TypeScript.
15
+
Make sure to read the [Setup Your Development Environment](./) article before continuing.
18
16
19
-
{% hint style="info" %}
20
-
Before following this guide, read the [Setup Your Development Environment](./) article.
21
-
{% endhint %}
17
+
## Create a Vite Package
18
+
19
+
Vite comes with a set of good presets to get you quickly up and running with libraries and languages. For example: Lit, Svelte, and Vanilla Web Components with both JavaScript and TypeScript.
22
20
23
-
1. Open a terminal and navigate to the project folder where you want to create your new Vite Package.
24
-
2. Run the following command in the folder to create a new Vite Package:
21
+
1. Open your terminal and navigate to the folder where you want to create the new Vite package.
22
+
2. Run the following command:
25
23
26
24
```bash
27
25
npm create vite@latest
28
26
```
29
27
30
-
This command will set up your new package and ask you to pick a framework and a compiler.
31
-
32
-
3. Enter `Client` as both the **Project Name** and **Package name** when prompted.
33
-
34
-
4. Choose **Lit** and **TypeScript** as the framework and language.
28
+
This command starts a setup prompt.
35
29
36
-
{% hint style="info" %}
37
-
For this tutorial, it is recommended to use the names given above. However, feel free to choose other names if preferred.
38
-
{% endhint %}
30
+
For this tutorial, it is recommended to use the names given below. However, feel free to choose other names if preferred.
39
31
40
-
<figure><imgsrc="../../extending/customize-backoffice/development-flow/images/vite-project-cli.jpg"alt=""><figcaption><p>Create vite command choices</p></figcaption></figure>
32
+
3. When prompted:
33
+
* Enter **client** as the **Project Name**.
34
+
* Enter **client** as the **Package name**.
35
+
* Select **Lit** as the framework.
36
+
* Select **TypeScript** as the variant.
41
37
42
-
This creates a new folder called `Client`, sets up our new project, and creates a `package.json` file, which includes the necessary packages. This is where all your source files live.
38
+
This creates a new folder called **client** with your projectfiles.
43
39
44
40
{% hint style="info" %}
45
-
Alternatively, you can skip the interactive prompts and use this command:
41
+
Alternatively, to skip the prompts, use this command:
46
42
47
43
```typescript
48
-
npmcreatevite@latestClient----templatelit-ts
44
+
npmcreatevite@latestclient----templatelit-ts
49
45
```
50
46
51
-
This will create a Vite Package with Lit and TypeScript in a folder called **Client**.
52
47
{% endhint %}
53
48
54
-
5. Navigate to the **Client**project folder and install the required packages:
49
+
4. Navigate into the new **client** folder and install the packages:
55
50
56
51
```bash
52
+
cd client
57
53
npm install
58
54
```
59
55
56
+
{% hint style="warning" %}
60
57
Before proceeding, ensure that you install the version of the Backoffice package compatible with your Umbraco installation. You can find the appropriate version on the [@umbraco-cms/backoffice npm page](https://www.npmjs.com/package/@umbraco-cms/backoffice).
58
+
{% endhint %}
61
59
62
-
6. Install the Backoffice package using the following command:
60
+
5. Install the Umbraco Backoffice package:
63
61
64
62
```bash
65
63
npm install -D @umbraco-cms/backoffice
66
64
```
67
65
68
-
{% hint style="info" %}
69
-
To avoid installing Umbraco’s sub-dependencies such as TinyMCE and Monaco Editor, you can add the `--legacy-peer-deps` flag:
70
-
{% endhint %}
66
+
6. To avoid installing additional dependencies such as TinyMCE or Monaco Editor,use the `--legacy-peer-deps` flag:
entry: "src/my-element.ts", // your web component source file
102
98
formats: ["es"],
103
99
},
104
-
outDir: "../App_Plugins/Client", // all compiled files will be placed here
100
+
outDir: "../App_Plugins/client", // all compiled files will be placed here
105
101
emptyOutDir: true,
106
102
sourcemap: true,
107
103
rollupOptions: {
108
104
external: [/^@umbraco/], // ignore the Umbraco Backoffice package in the build
109
105
},
110
106
},
111
-
base: "/App_Plugins/Client/", // the base path of the app in the browser (used for assets)
107
+
base: "/App_Plugins/client/", // the base path of the app in the browser (used for assets)
112
108
});
113
109
```
114
110
{% endcode %}
115
111
116
-
{% hint style="info" %}
117
-
The `outDir` parameter specifies where the compiled files are placed. In this example, they are stored in the `App_Plugins/Client` folder. If you are working with a different structure, such as a Razor Class Library (RCL) project, update this path to `wwwroot`.
118
-
{% endhint %}
112
+
The `outDir` parameter specifies where the compiled files are placed. In this example, they are stored in the `App_Plugins/client` folder. If you are working with a different structure, such as a Razor Class Library (RCL) project, update this path to `wwwroot`.
119
113
120
114
This alters the Vite default output into a **library mode**, where the output is a JavaScript file with the same name as the `name` attribute in `package.json`. The name is `client.js` if you followed this tutorial with no changes.
121
115
122
116
The source code that is compiled lives in the `src` folder of your package folder and that is where you can see a `my-element.ts` file. You can confirm that this file is the one specified as our entry on the Vite config file that we recently created.
123
117
124
-
{% hint style="info" %}
125
118
The `build:lib:entry` parameter can accept an array which will allow you to export multiple files during the build. You can read more about [Vite's build options here](https://vitejs.dev/config/build-options.html#build-lib).
126
-
{% endhint %}
127
119
128
-
Build the `ts` file in the `Client` folder so we can use it in our package:
120
+
10.Build the `ts` file in the **client** folder:
129
121
130
122
```bash
131
123
npm run build
132
124
```
133
125
134
126
## Watch for changes and build
135
127
136
-
If you like to continuously work on the package and have each change built, you can 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:
128
+
To continuously work on the package and have each change built, add a `watch`script in your `package.json` with `vite build --watch`.
129
+
130
+
The example below indicates where in the structure this change should be implemented:
@@ -148,15 +142,15 @@ If you like to continuously work on the package and have each change built, you
148
142
```
149
143
{% endcode %}
150
144
151
-
Then in the terminal, you can run `npm run watch`.
145
+
Run `npm run watch` in the terminal.
152
146
153
147
## Umbraco Package declaration
154
148
155
-
Declare your package to Umbraco via a file called `umbraco-package.json`. This should be added at the root of your package. In this guide, it is inside the `Client/public` folder so that Vite automatically copies it over every time it builds.
149
+
Declare your package to Umbraco via a file called `umbraco-package.json`. This should be added at the root of your package. The `umbraco-package.json` file should be located at `/App_Plugins/` or `/App_Plugins/{YourPackageName}` for Umbraco to detect it.
156
150
157
151
This example declares a Dashboard as part of your Package, using the Vite example element.
@@ -167,7 +161,7 @@ This example declares a Dashboard as part of your Package, using the Vite exampl
167
161
"type": "dashboard",
168
162
"alias": "My.Dashboard.MyExtension",
169
163
"name": "My Dashboard",
170
-
"element": "/App_Plugins/Client/client.js",
164
+
"element": "/App_Plugins/client/client.js",
171
165
"elementName": "my-element",
172
166
"meta": {
173
167
"label": "My Dashboard",
@@ -194,9 +188,9 @@ Learn more about the abilities of the manifest file in the [Umbraco Package Mani
194
188
195
189
#### Testing your package
196
190
197
-
To be able to test your package, you will need to run your site.
191
+
To test your package, run your site.
198
192
199
-
Before you do this, you need to make sure to run `npm run build` to compile your TypeScript files and copy them to the `App_Plugins/Client` folder.
193
+
Before doing this, make sure to run `npmrunbuild` to compile your TypeScript files and copy them to the `App_Plugins/client` folder.
200
194
201
195
{% hint style="warning" %}
202
196
If you try to include some of these resources via Visual Studio (VS), then make sure not to include TypeScript files. Otherwise, VS will try to include a few lines on your `.csproj` file to compile the TypeScript code that exists in your project folder. When you run your website, VS will try to compile these files and fail.
@@ -206,7 +200,7 @@ The final result looks like this:
Back in the `src/my-element.ts` file, you can update the `styles` property to make any styling changes. You can change the `background-color` of the `button` to white so it is more visible:
203
+
In the `src/my-element.ts` file, update the `styles` property to make any styling changes. You can change the `background-color` of the `button` to white so it is more visible:
0 commit comments