Load CSS files in Bellissima (V14+) #17049
Replies: 2 comments 10 replies
-
My use case that led me to create the issue was adding some branding to the backoffice - e.g. to set my own values for some of Umbraco's CSS variables. When adding a custom I'm not entirely sure how the proposed I'm not a frontender, so the new backoffice is a bit out of my comfort zone, but I think that a new |
Beta Was this translation helpful? Give feedback.
-
Hi @iOvergaard 👋 For me I would have the approach of this JSON file containing two entries, one for the main entrypoint JS that can then register other manifests as per normal, and the second entry to be for the CSS file I want to register as a global CSS and its path, along with weight. With the weight I can determine the order that the CSS files load in then. {
"$schema": "../../MyPackage.Website/umbraco-package-schema.json",
"id": "myPackage",
"name": "My Package",
"allowPackageTelemetry": true,
"version": "1.0.0",
"extensions": [
{
"name": "My Package EntryPoint",
"alias": "mypackage.entrypoint",
"type": "backofficeEntryPoint",
"js": "/app_plugins/MyPackage/MyPackage.js"
},
{
"name": "My Custom CSS",
"alias": "my.custom.css",
"type": "globalCss",
"css": "/app_plugins/MyPackage/css/custom.css",
"weight": -1
}
]
} |
Beta Was this translation helpful? Give feedback.
-
From time to time, you will need to load global CSS files into the Backoffice. This is useful if you need to set global CSS variables or even overwrite some of Umbraco's own CSS variables.
ℹ️ This is different from the CSS needed for Web Components, where a bundler most likely will take care of inlining your styles or making sure to load the CSS files for you.
As of writing this, the only way to mount a raw CSS file into the Backoffice is to register an extension of type "backofficeEntryPoint" and in its JavaScript module file create a link tag and add it to the document:
umbraco-package.json
entrypoint.js
There are various ways where we can make this easier for the developer. For one, we can add a function that lets you specify the CSS more directly and the Backoffice can load it either before or after itself is loaded:
This still requires the developer to register an entrypoint, however. It also does not solve another issue, which could best be described as "load order" or "weight" where you might want to inject a stylesheet into a very specific order due to CSS specificity, where the order matters. The previous Backoffice (Belle) supported a
css
array in itspackage.manifest
file where you could load CSS files. They would be lazy-loaded and thus not necessarily loaded in any known order.I think we need some resemblance of the
css
array introduced in Bellissima, but the theme I want to discuss here is what people need. Based on this comment by Anders Bjerner, we could get the idea that an extension type of "CSS" with some kind of weight/order would solve some needs. This is certainly doable, but what would the format look like? Where does one register a CSS file?Beta Was this translation helpful? Give feedback.
All reactions