Arduino HomeDing Blog Archive

Thoughs and records on IoT, Web Sites and Microprocessors.

Single-File Components Details - 1

A box labeled sfc with 3 contained boxes labeled html, JS and CSS.

Details on the SFC implementation: File Names and Extensions

File Names and Tag Names

In case there is a single custom element file (not component bundles and no extension) the filename is identical to the tag name. This helps understanding the file content right from the filename.

As required by the HTML standard the tag name must contain a ‘-’ (minus) character to avoid conflicts with the standard HTML elements so this applies to file-names as well.

As a best practice libraries for custom elements like for css variables is to use a common prefix like:

As a bad practice, names line my-element, todo-list, ui-button or custom-range-input are formally correct but risking conflicts.

This collection of custom elements is using the u- prefix. (u looks like the micro (µ) sign that cannot be used).

File Extensions

SFC components are regular HTML formatted files !

To allow best support from the tools (I use vscode most of the times) the file extension used is *.sfc that can be mapped in the user or workspace setting to html formatting. e.g.:

"files.associations": {
  "*.sfc": "html"
}

This file extension should also work for other environments.

See also

Tags

#sfc