CssImport without full restart

Do I need a full application restart for each change in my.css when imported this way?
@Route @CssImport(value = "./css/my.css")
I am using IntelliJ. Maybe my settings is wrong?

(I know about styles.css)

Yes restart is needed or you could try hot reload

Typically css changes trigger live reloads automatically, but it depends on how you run the app.

https://vaadin.com/docs/v14/flow/configuration/live-reload/#frontend-changes

“Code in the application’s frontend folder (JS/TS/CSS files) is monitored by webpack-dev-server when running the application in development mode. Adding, modifying or removing a file in this folder triggers recompilation of the frontend bundle and subsequent a browser reload.”

Or, for V23 https://vaadin.com/docs/latest/configuration/live-reload/#front-end-changes

“As of Vaadin 23.2, frontend build and live reload features are officially handled by Vite by default. However, webpack is still supported by enabling its associated feature flag. See the webpack Feature Flag section for how to do this. Support for webpack ends with the next major release — with Vaadin 24.”

Code in the application’s frontend folder (JS/TS/CSS files) is monitored by vite-dev-server when running the application in development mode. Adding, modifying, or removing a file in this folder triggers recompilation of the front-end bundle and a browser reload."

My CSS was in the folder src/main/resources/META-INF/resources/frontend/css/my.css, when I moved it to frontend/css/my.css I have live reload. I have a multi-module setup. If I put my CSS in META-INF in my shared lib module, it is loaded. Now I am trying to put it in my frontend-lib, which is loaded by Vite, but cannot find out the path to use for frontend-lib/css/my.css. The alias seems not to work. https://github.com/sveine/vaadin-small-business-starter/tree/main/core-module/frontend-lib/css

Yea! Found out how: @CssImport(value = "./../../core-module/frontend-lib/css/my.css")

Nice! I can also warmly recommend the theme folder approach instead of @CssImport. Afaik it should work well with multi-module setups.

https://vaadin.com/docs/v14/ds/customization/custom-theme

That relative link looks like it’s going to break in production mode

Edit: nvm. it could work

It works! First I did was to build my docker image. Vite creates the bundle

It is also working with SCSS: https://github.com/sveine/vaadin-small-business-starter/blob/2906c7412390733c217be5de386b27dd53ba75d1/small-business-starter-vaadin/src/main/java/com/smallbusiness/application/views/multimodule/CoreModuleTestingView.java#L21

Keep in mind that scss isn’t official supported by Vaadin, so if it breaks you are on your own :sweat_smile:

Vite handle it. It is much easier to use SCSS in Vite than WebPack. I only add @NpmPackage(value = "sass", version = "1.55.0"). You may think about components and ShadowDOM, then I think only CSS can be used.

well, SCSS compiles into plain old CSS, so there isn’t really anything in it that Vaadin would need to support per se. It works just fine with components/shadow dom too, as long as you make sure that the resulting CSS is split into separate files correctly (or stick to styling components using ::part() in light dom css)

I was more referring to the possibility that Vaadin switches from vite to something else like currently with webpack → vite and people complaining that their webpack config doesn’t work anymore :sweat_smile:

right, yes, build process changes might require a bit of tweaking to keep the SCSS compilation working