Since Vaadin components are based in Web Components, you have to put the CSS in an HTML file and load it with the @HtmlImport annotation:
@HtmlImport("frontend://styles/shared-styles.html")
public class MainLayout extends Div implements RouterLayout {
}
In the shared-styles.html file (located in src/main/webapp/frontend/styles) you can add any CSS rules as follows:
<custom-style>
<style>
... CSS here ...
</style>
</custom-style>
Lumo defines CSS custom properties that allow you to quickly modify the look and feel of an app:
<custom-style>
<style>
html {
--lumo-font-family: Courier, monospace;
--lumo-border-radius: 20px;
--lumo-base-color: #fafbfc;
--lumo-primary-color: #00b4f0;
}
</style>
</custom-style>
You can add CSS class names to any UI component using the addClassName and addClassNames methods:
addClassName("custom");
This class name can be used in a selector in the shared-styles-html file:
.custom {
color: red;
}
Deployment
To deploy a Vaadin Flow application in a production environment, you must add the vaadin-maven-plugin in a Maven profile in the pom.xml file and compile the project specifying the name of the profile (for example, mvn clean package -PproductionMode). This performs three main tasks:
-
Transpilation: Converts ES6 JavaScript to ES5 JavaScript to support older browsers.
-
Minimization: Makes JavaScript files smaller.
-
Bundling: Bundling: Stitching together a group of modules into a single file.
For details about how to add the vaadin-maven-plugin, see https://vaadin.com/docs/v10/flow/production/tutorial-production-mode-basic.html.
In order to use the resources created by the vaadin-maven-plugin, you have to enable production mode using the @VaadinServletConfiguration annotation as follows:
@WebServlet(urlPatterns = "/*", asyncSupported = true,
initParams = { // optional
@WebInitParam(name = "frontend.url.es6", value = "http://mydomain.com/es6/"),
@WebInitParam(name = "frontend.url.es5", value = "http://mydomain.com/es5/") }
)
@VaadinServletConfiguration(productionMode = true)
public static class MainVaadinServlet extends VaadinServlet {}
You can also use system properties to override the @WebInitParam annotations. For example, you can pass the properties to the Jetty Maven Plugin as follows:
mvn jetty:run -Dvaadin.frontend.url.es6=http://mydomain.com/es6/ -Dvaadin.frontend.url.es5=http://mydomain.com/es5/
Notice that if you run the application using the Jetty Maven Plugin in production mode, you have to run it using mvn jetty:run-exploded.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}