springpolymervaadinstylesheetvaadin-flow

Where should I place my Vaadin 10+ static files?


In Vaadin 10-14, where should I place my static files, such as CSS, JavaScript, and Polymer templates? How about static files such as images?

Also, how do I import these files in Vaadin? Is there a difference between Vaadin 14 with npm and Vaadin 10-13 with bower?


Solution

  • All paths are relative to the project root, e.g. where the pom.xml file is located in a Maven project.

    JavaScript imported using @JsModule uses strict mode. Among other things, this means that global variables must be defined on the window object, window.x = ..., instead of just x = ....


    Vaadin 14 with npm

    Non-Spring Boot projects (war packaging)

    Spring Boot projects (jar packaging)

    Add-ons (jar packaging)


    Vaadin 10-13, Vaadin 14 in compatibility mode

    Non-Spring Boot projects (war packaging)

    Spring Boot projects and add-ons (jar packaging)


    Footnotes

    [1] The @JsModule and @CssImport annotations can also be used for importing from an npm package. In this case, the path is defined as @JsModule("@polymer/paper-input") or @CssImport("some-package/style.css"). Paths referring to the local frontend directory should be prefixed with ./

    [2] The @StyleSheet annotation can also be used in Vaadin 14 with npm. The same paths as in V10-V13 can be used, including the context:// protocol @StyleSheet("context://style.css"), which resolves the path relative to the context path of the web application, like other static files. Styles included this way may cause issues with web components.

    [3] The @JavaScript annotation can also be used in Vaadin 14 with npm. The V14 /frontend folder should then be used,.