Class VaadinPlugin
This class is a porting of Vaadin Maven prepare-frontend and build-frontend mojos.
-
Method Summary
Modifier and TypeMethodDescriptionvoidbuildFrontend(BiConsumer<String, byte[]> emitter) Builds the frontend bundle.voidclean()Cleans up generated frontend files if the corresponding configuration setting is enabled.BiConsumer<String, byte[]> createGeneratedResourceEmitter(Iterable<Path> packagedRootDirectories, io.quarkus.deployment.annotations.BuildProducer<io.quarkus.deployment.builditem.GeneratedResourceBuildItem> producer) Creates the emitter that registers the generated Vaadin files with the application.static VaadinPluginof(VaadinBuildTimeConfig vaadinConfig, io.quarkus.bootstrap.model.ApplicationModel applicationModel, Path outputTarget) Creates a new instance of the VaadinPlugin based on the provided configuration and application model.voidChecks that node and npm tools are installed and creates or updates `package.json` and the frontend build tool configuration files.
-
Method Details
-
of
public static VaadinPlugin of(VaadinBuildTimeConfig vaadinConfig, io.quarkus.bootstrap.model.ApplicationModel applicationModel, Path outputTarget) throws io.quarkus.builder.BuildException Creates a new instance of the VaadinPlugin based on the provided configuration and application model. If necessary, it attempts to load workspace information for the plugin.- Parameters:
vaadinConfig- the Vaadin build time configuration.applicationModel- the application model representing the current application.outputTarget- the target directory for output operations.- Returns:
- an instance of VaadinPlugin initialized with the given parameters.
- Throws:
io.quarkus.builder.BuildException- if workspace information cannot be loaded or an error occurs during the process.
-
prepareFrontend
public void prepareFrontend() throws io.quarkus.builder.BuildExceptionChecks that node and npm tools are installed and creates or updates `package.json` and the frontend build tool configuration files.
Copies frontend resources available inside `.jar` dependencies to `node_modules` when building a jar package.- Throws:
io.quarkus.builder.BuildException- if any error occurs.
-
buildFrontend
public void buildFrontend(BiConsumer<String, byte[]> emitter) throws io.quarkus.builder.BuildExceptionBuilds the frontend bundle.
It performs the following actions when creating a package:- Update
Constants.PACKAGE_JSONfile with theNpmPackageannotations defined in the classpath, - Copy resource files used by flow from `.jar` files to the `node_modules` folder
- Install dependencies by running
npm install - Update the
FrontendUtils.IMPORTS_NAMEfile imports with theJsModuleThemeandJavaScriptannotations defined in the classpath, - Update
FrontendUtils.VITE_CONFIGfile.
Once the build is done the generated files are handed to the emitter and the build info token file is deleted from the build output directory. Nothing is deleted before the files that have to reach the application whichever way it is packaged are known to have reached it: a file that cannot be read fails the build, and so does one that was not emitted. Deleting the token file after it failed to reach the application would package an application without a flow-build-info.json while the build reports success.
- Parameters:
emitter- generated files emitter.- Throws:
io.quarkus.builder.BuildException- if any error occurs.
- Update
-
createGeneratedResourceEmitter
public BiConsumer<String,byte[]> createGeneratedResourceEmitter(Iterable<Path> packagedRootDirectories, io.quarkus.deployment.annotations.BuildProducer<io.quarkus.deployment.builditem.GeneratedResourceBuildItem> producer) Creates the emitter that registers the generated Vaadin files with the application.The emitter skips the files that packaging already copies into the artifact by itself, so that they are not added a second time.
- Parameters:
packagedRootDirectories- the directories Quarkus packages the application from, as reported byArchiveRootBuildItem.getRootDirectories().producer- the producer registering the files with the application.- Returns:
- the emitter to pass to
buildFrontend(BiConsumer). - See Also:
-
clean
public void clean()Cleans up generated frontend files if the corresponding configuration setting is enabled. The process involves creating a new cleaning task with specific options derived from the plugin adapter's configuration and executing it. If an error occurs during the execution of the clean task, it is logged for debugging purposes.The cleanup operation ensures the following: - Deletes the generated frontend files in the `node_modules` folder. - Utilizes the directory configurations such as frontend directory, npm folder, and generated TypeScript folder to locate the files. - Makes use of the `TaskCleanFrontendFiles` for cleanup operations.
Unlike the Vaadin Maven plugin, which only cleans when a frontend bundle has been built, this runs after every successful build. This plugin always reports frontend hotdeploy as enabled, so even a build that reuses a prebuilt production bundle writes package.json, the Vite configuration files, tsconfig.json and types.d.ts into the project directory. Skipping the cleanup for those builds would leave the files behind.
Errors are logged rather than propagated, including unchecked ones. This method runs as a Quarkus build closeable, which cannot fail the build and logs anything thrown out of here at debug level only, so an error that is not caught here goes unnoticed.
-