省略加载未使用组件的主题和避免在 Vaadin 23 中进行网络加载。

huangapple go评论58阅读模式
英文:

Omit theme loading of unused components and avoid network load in Vaadin 23

问题

我刚刚意识到我的Vaadin Web应用程序在总共8MB的JavaScript网络加载印记中至少加载了3MB的未使用的JS主题库。如何防止这种情况发生?

最突出的三个是:

  • 1600kb的Vaadin图表 @vaadin_charts_theme_lumo_vaadin-chart__js.js
  • 大于340kb的Vaadin地图 @vaadin_map_theme_lumo_vaadin-map__js.js
  • 大于310kb的Vaadin富文本编辑器 @vaadin_rich-text-editor_theme_lumo_vaadin-rich-text-editor__js.js

是否可以通过Vite的某种方式来排除它们?
Vaadin版本:23.3.4(非生产模式)

我没有使用任何商业组件,并已尝试在pom.xml中明确排除它们,还从package.json中删除它们,然后重新运行了npm i

省略加载未使用组件的主题和避免在 Vaadin 23 中进行网络加载。

英文:

I just realized that my Vaadin Web Application loads at least 3mb of unused JS theme libraries out of an 8Mb overall javascript network loading footprint.
How can this be prevented?

The three most prominent

  • 1600kb vaadin charts @vaadin_charts_theme_lumo_vaadin-chart__js.js
  • >340kb vaadin map @vaadin_map_theme_lumo_vaadin-map__js.js
  • >310kb vaadin rich text editor @vaadin_rich-text-editor_theme_lumo_vaadin-rich-text-editor__js.js

Can this be excluded with Vite somehow?
Vaadin version: 23.3.4 (non-production mode)

省略加载未使用组件的主题和避免在 Vaadin 23 中进行网络加载。

I am not using any of the commercial components and have tried to explicitly exclude them from the pom.xml and also removed them from package.json, then started npm i again

		<dependency>
		<groupId>com.vaadin</groupId>
		<artifactId>vaadin</artifactId>
		<exclusions>
			
			<exclusion>
				<groupId>com.vaadin.addon</groupId>
				<artifactId>vaadin-charts</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.vaadin</groupId>
				<artifactId>vaadin-rich-text-editor-flow</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.vaadin</groupId>
				<artifactId>vaadin-map-flow</artifactId>
			</exclusion> 
            <!-- [..] -->

答案1

得分: 7

在开发模式下,会加载许多额外的JS。应该在生产模式下运行测试,在此模式下,会扫描实际使用的组件,并创建一个优化的JS捆绑包。

通常在开发过程中,没有必要阻止从本地主机加载几兆字节的JS。

英文:

In development mode, a lot of extra JS is loaded. You should run your test in production mode where the application is scanned for the components you actually use and an optimized JS bundle is created.

There is usually no need to prevent some MB of JS from being loaded from localhost while developing.

huangapple
  • 本文由 发表于 2023年2月26日 18:56:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75571497.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定