Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite does not work with custom frontend directory #14046

Closed
mcollovati opened this issue Jun 23, 2022 · 2 comments · Fixed by #14152
Closed

Vite does not work with custom frontend directory #14046

mcollovati opened this issue Jun 23, 2022 · 2 comments · Fixed by #14152

Comments

@mcollovati
Copy link
Collaborator

Description of the bug

When using Vite is a Spring Boot project with a custom frontend folder configured in vaadin-maven-plugin, the dev server seems to start, but the java application keeps restarting infinitely.

Main problem seems to be that in vite.generated.ts there a root key whose value is hard-coded to 'frontend'.
This can be fixed in vite.config.ts

const customConfig: UserConfigFn = (env) => ({
  // Here you can add custom Vite parameters
  // https://vitejs.dev/config/
  root: 'src/main/frontend'
});

But then there are failure in themes compilation, because they are still using frontend/generated directory instead to be nested into the custom frontend folder.

The workaround for this is to set also the generatedTsFolder setting in vaadin-maven-plugin, pointing to a subfolder of the custom generated frontend dir.

<generatedTsFolder>src/main/frontend/generated</generatedTsFolder>

However this does not make Vite work because there are other issues with custom frontend folder.
This is slightly related to #12880).
For example some hard-coded relative path that assumes files are in frontend/generated (for example ../../target/xyz).

Additional note: vite.generated.ts has the following confiuration that may also be wrong with custom frontend directory

const allowedFrontendFolders = [
  // other settings
  path.resolve(frontendFolder, '../node_modules')
];

Minimal reproducible example

Download an application from start.vaadin.com with Vite enabled and add the following configuration to vaadin-maven-plugin.

<configuration>
    <frontendDirectory>src/main/frontend</frontendDirectory>
</configuration>

Expected behavior

Vite dev serve works as when using default frontend directory

Actual behavior

  1. Dev server does not serve frontend files and Java server continously restarts itself
  2. If workarounds are applyed, compilation fails due to "file not found" errors because of wrong relative paths

Versions:

- Vaadin / Flow version: 23.1.1
- Java version: 11
- OS version: Ubuntu 21.10
- Browser version (if applicable):
- Application Server (if applicable):
- IDE (if applicable):
- Development mode
- Project from start.vaadin.com
@mcollovati mcollovati added bug vite Tickets related to vite support labels Jun 23, 2022
@mshabarov mshabarov added this to Needs triage in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) via automation Jun 23, 2022
@mshabarov mshabarov moved this from Needs triage to P1 - High priority in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) Jun 23, 2022
@mcollovati mcollovati moved this from P1 - High priority to WIP in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) Jun 29, 2022
@mcollovati mcollovati self-assigned this Jun 29, 2022
mcollovati added a commit that referenced this issue Jul 7, 2022
Fixes Vite configuration to work with a custom frontend directory.
Also rewrite theme css to resolve urls for assets defined in theme.json

Fixes #14046
Fixes #14102
mcollovati added a commit that referenced this issue Jul 8, 2022
Fixes Vite configuration to work with a custom frontend directory.
Also rewrite theme css to resolve urls for assets defined in theme.json

Fixes #14046
Fixes #14102
@mcollovati mcollovati moved this from Product backlog to In progress in OLD Vaadin Flow ongoing work (Vaadin 10+) Jul 13, 2022
@mcollovati mcollovati moved this from In progress to Iteration Reviews in OLD Vaadin Flow ongoing work (Vaadin 10+) Jul 13, 2022
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Iteration Reviews to Done - pending release Jul 26, 2022
OLD Vaadin Flow bugs & maintenance (Vaadin 10+) automation moved this from WIP to Closed Jul 26, 2022
vaadin-bot pushed a commit that referenced this issue Jul 26, 2022
Fixes Vite configuration to work with a custom frontend directory.
Also rewrite theme css to resolve urls for assets defined in theme.json

Fixes #14046
Fixes #14102
mcollovati pushed a commit that referenced this issue Jul 26, 2022
#14222)

Fixes Vite configuration to work with a custom frontend directory.
Also rewrite theme css to resolve urls for assets defined in theme.json

Fixes #14046
Fixes #14102
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 23.1.6.

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 23.2.0.beta1 and is also targeting the upcoming stable 23.2.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment