You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to be able to read the template sources (which are in the frontend folder)
both in development and production mode
How it works today
Webpack creates a stats.json file containing the actual sources for all files included in the compilation
In dev mode, stats.json are read through the webpack dev server
In production mode, stats.json is read from the classpath
We drop unnecessary stuff from stats.json to make it smaller
How it could work with Vite
In dev mode, we can read the template directly from the Vite dev server (we could do this for webpack also if we want)
In production, copy all template sources to a resources directory (META-INF/VAADIN/frontend) and read them from the classpath on demand
Webpack generated a stats.json containing all template sources that can be requested so that we can parse the template contents. (See stats-plugin)
Template sources are requested through: FrontendUtils::getStatsContent
from which the sources in received stats.json content is searched with BundleLitParser::getSourceFromStatistics or BundleParser::getSourceFromStatistics for PolymerTemplate
Source requests are made in NpmTemplateParser and LitTemplateParserImpl as a possible place to get template sources in the method getTemplateContent.
Suggested changes
Alias Frontend -> frontendFolder in vite.config.ts
Template source can be retrieved directly from Vite by a direct request of filename (instead of by stats.json parsing with Webpack). The DevModeHandler interface currently provides a method (prepareConnection) which directly opens a connection the Webpack dev-server (used by e.g. FrontendUtils::getStatsContent) meaning that Webpack specifics are not abstracted by the interface. Need to add a method to DevModeHandler interface for retrieving template source so that the Webpack / Vite - specific details can be hidden inside the WebpackHandler / ViteHandler interfaces respectively.
In production mode, the current implementation reads stats.json from either the classpath (default) or from an external URL (primarily added to support portlets). With Vite, we need to also store the template sources (in some format) so that they are available at runtime.
During build-frontend with Vite, copy all template sources to a resources directory.
In BundleLitParser, decouple the parsing of stats.json from the parsing of the template itself so that the first can vary (Webpack / Vite). This could be done by either having an interface with two implementations, something like TemplateSourceAccess / WebpackTemplateSourceAccess / ViteTemplateSourceAccess (or just an if-condition on the feature flag). Effectively, BundleLitParser::getSourceFromStatistics would go to WebpackTemplateSourceAccess and the Vite implementation would just simply read the template sources outright from the classpath.
The text was updated successfully, but these errors were encountered:
We need to be able to read the template sources (which are in the frontend folder)
both in development and production mode
How it works today
Webpack creates a stats.json file containing the actual sources for all files included in the compilation
In dev mode, stats.json are read through the webpack dev server
In production mode, stats.json is read from the classpath
We drop unnecessary stuff from stats.json to make it smaller
How it could work with Vite
In dev mode, we can read the template directly from the Vite dev server (we could do this for webpack also if we want)
In production, copy all template sources to a resources directory (META-INF/VAADIN/frontend) and read them from the classpath on demand
Webpack generated a stats.json containing all template sources that can be requested so that we can parse the template contents. (See stats-plugin)
Template sources are requested through: FrontendUtils::getStatsContent
from which the sources in received stats.json content is searched with BundleLitParser::getSourceFromStatistics or BundleParser::getSourceFromStatistics for PolymerTemplate
Source requests are made in NpmTemplateParser and LitTemplateParserImpl as a possible place to get template sources in the method getTemplateContent.
Suggested changes
The text was updated successfully, but these errors were encountered: