Hi,
I’m prototyping use of Vaadin in an existing application. The application has a chrome that is developed primarily in React, and embeds server-side generated content within it - this latter is what I am considering migrating to Vaadin.
The application uses servlets and guice, so I have created a GuiceServletModule
to install the VaadinServlet
. I have also created a simple component and a WebComponentExporter
for it. This has all been created in a new maven jar which will be a dependency of the WAR.
VaadinApplicationServlet and GuiceServletModule:
public class VaadinApplicationServletModule extends ServletModule {
private static final String VAADIN = "/vaadin/*";
@Override
protected void configureServlets() {
super.configureServlets();
serve(VAADIN).with(VaadinApplicationServlet.class);
}
@Singleton
public static class VaadinApplicationServlet extends VaadinServlet {}
}
MyComponent
public class MyComponent extends Div {
public MyComponent() {
super();
Paragraph placeholder = new Paragraph();
placeholder.setText("Vaadin application");
this.add(placeholder);
}
}
MyComponentExporter:
public class MyComponentExporter extends WebComponentExporter<MyComponent> {
public MyComponentExporter() {
super("my-component");
}
@Override
protected void configureInstance(WebComponent<MyComponent> webComponent, MyComponent component) {
}
}
My pom includes the following - I’m using production mode as I figured it would be a simpler initial goal as I get set up:
<properties>
<vaadin.version>14.3.0</vaadin.version>
<vaadin.productionMode>true</vaadin.productionMode>
<vaadin.compatibilityMode>false</vaadin.compatibilityMode>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
My HTML head includes the following:
<script type='text/javascript'
src='/context-root/vaadin/VAADIN/build/webcomponentsjs/webcomponents-loader.js'>
</script>
<script type='module'
src='/context-root/vaadin/web-component/my-component.js'>
</script>
The page successfully loads the webcomponents-loader, but always returns a 404 for my-component.js. When I run a mvn package
, I can see that target/frontend/my-component.js
is created, and if I inspect the minified JS output I can see reference to my-component there too. I have tried both running with the module open in my IDE (InjelliJ) and installing and resolving from my local maven repository, with the same results.
I’m sure there’s something simple I’ve overlooked, or some minor quirk of my use-case that I haven’t accounted for. A second pair of eyes would be greatly appreciated!
Edit: If I run in debug mode, I get an NPE since the DevModeHandler
has not been initialised. This may give some indication as to what I’ve missed/messed.