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] Template contents for Lit-/PolymerBundleParser (StatsPlugin) #12051

Closed
5 tasks done
gilberto-torrezan opened this issue Oct 15, 2021 · 1 comment
Closed
5 tasks done
Assignees
Labels
enhancement vite Tickets related to vite support

Comments

@gilberto-torrezan
Copy link
Contributor

gilberto-torrezan commented Oct 15, 2021

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.
@gilberto-torrezan gilberto-torrezan added enhancement vite Tickets related to vite support labels Oct 15, 2021
@gilberto-torrezan gilberto-torrezan added this to To do in Frontend build optimization via automation Oct 15, 2021
@joheriks joheriks moved this from To do to In progress in Frontend build optimization Oct 26, 2021
@joheriks joheriks self-assigned this Oct 26, 2021
@joheriks
Copy link
Contributor

joheriks commented Nov 9, 2021

Fixed by #12204

@joheriks joheriks closed this as completed Nov 9, 2021
Frontend build optimization automation moved this from In progress to Done Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement vite Tickets related to vite support
Development

No branches or pull requests

2 participants