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: docs/_guide/you-will-need.md
+58-1Lines changed: 58 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,4 +23,61 @@ Please note this list may increase over time. Catalyst will never ship with poly
23
23
24
24
When using build tools, some JavaScript minifiers modify the class name that Catalyst relies on. You know you have an issue if you encounter the error `"c" is not a valid custom element name`.
25
25
26
-
A best practice is to allow class names that end with `Element`. For instance, for Terser, you can use the following config: `{ keep_classnames: /Element$/ }`
26
+
The preferred way to handle this is to disable renaming class names in your build tools.
27
+
28
+
#### ESBuild
29
+
30
+
When using ESBuild you can turn off all class and function name minification with the [`keep_names`](https://esbuild.github.io/api/#keep-names) option. Setting this to `true` in your build will opt-out all classes and all functions from minification.
31
+
32
+
33
+
```ts
34
+
{ keep_names: true }
35
+
// Or --keep-names on the CLI
36
+
```
37
+
38
+
#### Terser
39
+
40
+
When using Terser you have a bit more control, and can explicitly opt just classes, or just certain class names out of minification. For example to opt-out class names that end with `Element` you can set the following config:
41
+
42
+
```ts
43
+
{ keep_classnames:/Element$/ }
44
+
```
45
+
46
+
It is also possible to set `keep_classnames` to `true` (or pass `--keep-classnames` to the CLI tool), which will opt-out all class names. [You can read more about the minification options on Terser's docs](https://terser.org/docs/api-reference#minify-options)
47
+
48
+
#### SWC
49
+
50
+
When using SWC you can use the `keep_classnames` option just like Terser. As SWC also handles Transpilation, you should be sure to enable native class syntax by specifiying `target` to at least `es2016`. [Take a look at the SWC docs for more about compression options](https://swc.rs/docs/configuration/minification#jscminifycompress).
51
+
52
+
```json
53
+
{
54
+
"jsc": {
55
+
"target": "es2016",
56
+
"minify": {
57
+
"compress": {
58
+
"keep_classnames": true
59
+
}
60
+
}
61
+
}
62
+
}
63
+
```
64
+
65
+
#### Other alternatives
66
+
67
+
If your tool chain does not support opting out of minification, or if you would prefer to keep name minification on, you can instead selectively re-assign the `name` field to Catalyst controllers:
68
+
69
+
```ts
70
+
@controller
71
+
classUserListextendsHTMLElement {
72
+
static name ='UserList'
73
+
}
74
+
```
75
+
76
+
TypeScript decorators only support _class declarations_ which means you will still need to keep the class name between `class` and `extends`. For example the following will be a SyntaxError:
0 commit comments