Skip to content

Commit 1da0954

Browse files
committed
Init and add demo
1 parent c8102d9 commit 1da0954

File tree

15 files changed

+986
-26
lines changed

15 files changed

+986
-26
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ hs_err_pid*
3333
.classpath
3434
.project
3535

36+
#vaadin/node webpack/frontend stuff
37+
# Ignore Node
38+
node/
39+
40+
# The following files are generated/updated by vaadin-maven-plugin
41+
node_modules/
42+
43+
# Vaadin
44+
package.json
45+
package-lock.json
46+
webpack.generated.js
47+
webpack.config.js
48+
tsconfig.json
49+
types.d.ts
50+
vite.config.ts
51+
vite.generated.ts
52+
**/src/main/frontend/generated/
53+
**/src/main/frontend/index.html
54+
**/src/main/bundles/
55+
*.lock
56+
3657
# == IntelliJ ==
3758
*.iml
3859
*.ipr

.run/Run Demo.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Run Demo" type="Application" factoryName="Application">
3-
<option name="MAIN_CLASS_NAME" value="software.xdev.Application" />
3+
<option name="MAIN_CLASS_NAME" value="software.xdev.vaadin.Application" />
44
<module name="vaadin-package-json-optimizer-demo" />
55
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
66
<extension name="coverage">

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1.0.0
2+
3+
_Init_

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,95 @@
33

44
# `package.json` optimizer for Vaadin
55

6+
Patches `package.json` and replaces unused packages with an empty package.
7+
8+
This also prevents the installation of the corresponding transitive dependencies and lowers the overall attack surface.
9+
10+
As of Vaadin 24.8 this results in the following:
11+
* at least 280 fewer packages (-55%): ~500 → ~210
12+
* 80MB fewer required storage space (-40%): ~210MB → ~130MB
13+
* overall faster build/`npm install` by processing/downloading less packages
14+
15+
Please note that this is currently intended as a stopgap measure until Vaadin implements improvements upstream.
16+
17+
<details><summary>Currently these npm package groups are overwritten with an empty package</summary>
18+
19+
* `glob`'s and `rollup-plugin-visualizer`'s CLI packages
20+
* Vaadin never uses their CLI and only library methods
21+
* Incorrectly declared dependencies of `transform-ast`
22+
* All Vaadin Pro components and their corresponding packages
23+
* Unused dependencies of `workbox`
24+
25+
Full details are available in the [source code](./vaadin-package-json-optimizer/src/main/java/software/xdev/vaadin/vpjo/VPJOptimizer.java).
26+
27+
</details>
28+
29+
## Usage
30+
31+
`package.json` needs to be modified BEFORE the Vaadin installs all dependencies using `npm install`.
32+
33+
This needs to happen in 2 places:
34+
1. When building the frontend with the build-frontend goal
35+
```xml
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.codehaus.mojo</groupId>
40+
<artifactId>exec-maven-plugin</artifactId>
41+
<version>...</version>
42+
<executions>
43+
<execution>
44+
<id>patch-package-json-overrides</id>
45+
<phase>compile</phase>
46+
<goals>
47+
<goal>java</goal>
48+
</goals>
49+
<configuration>
50+
<mainClass>software.xdev.vaadin.vpjo.Launcher</mainClass>
51+
<arguments>
52+
<argument>${project.basedir}</argument>
53+
<argument>${project.build.directory}</argument>
54+
</arguments>
55+
<includeProjectDependencies>false</includeProjectDependencies>
56+
<includePluginDependencies>true</includePluginDependencies>
57+
<executableDependency>
58+
<groupId>software.xdev</groupId>
59+
<artifactId>vaadin-package-json-optimizer</artifactId>
60+
</executableDependency>
61+
</configuration>
62+
</execution>
63+
</executions>
64+
<dependencies>
65+
<dependency>
66+
<groupId>software.xdev</groupId>
67+
<artifactId>vaadin-package-json-optimizer</artifactId>
68+
<version>...</version>
69+
</dependency>
70+
</dependencies>
71+
</plugin>
72+
...
73+
```
74+
2. When running in dev mode
75+
```xml
76+
<profiles>
77+
<profile>
78+
<id>dev</id>
79+
<activation>
80+
<activeByDefault>true</activeByDefault>
81+
</activation>
82+
<dependencies>
83+
<!-- Only needed as dependency during development not in production! -->
84+
<dependency>
85+
<groupId>software.xdev</groupId>
86+
<artifactId>vaadin-package-json-optimizer</artifactId>
87+
<version>...</version>
88+
</dependency>
89+
</dependencies>
90+
</profile>
91+
...
92+
```
93+
94+
For more information have a look at the [demo's `pom.xml`](./vaadin-package-json-optimizer-demo/pom.xml).
695

796
## Installation
897
[Installation guide for the latest release](https://github.com/xdev-software/vaadin-package-json-optimizer/releases/latest#Installation)

vaadin-package-json-optimizer-demo/pom.xml

Lines changed: 206 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,131 @@
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2727
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2828

29-
<mainClass>software.xdev.Application</mainClass>
29+
<mainClass>software.xdev.vaadin.Application</mainClass>
30+
31+
<!-- Dependency-Versions -->
32+
<vaadin.version>24.8.8</vaadin.version>
33+
34+
<org.springframework.boot.version>3.5.5</org.springframework.boot.version>
3035
</properties>
3136

37+
<dependencyManagement>
38+
<dependencies>
39+
<dependency>
40+
<groupId>com.vaadin</groupId>
41+
<artifactId>vaadin-bom</artifactId>
42+
<type>pom</type>
43+
<scope>import</scope>
44+
<version>${vaadin.version}</version>
45+
</dependency>
46+
47+
<!-- Spring Boot -->
48+
<!-- This bom provides versions for ~500 dependencies -->
49+
<!-- Nearly at the end so that it doesn't accidentally overwrite other versions -->
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-dependencies</artifactId>
53+
<version>${org.springframework.boot.version}</version>
54+
<type>pom</type>
55+
<scope>import</scope>
56+
</dependency>
57+
</dependencies>
58+
</dependencyManagement>
59+
3260
<dependencies>
3361
<dependency>
34-
<groupId>software.xdev</groupId>
35-
<artifactId>vaadin-package-json-optimizer</artifactId>
36-
<version>${project.version}</version>
62+
<groupId>com.vaadin</groupId>
63+
<artifactId>vaadin-core</artifactId>
64+
<exclusions>
65+
<!-- No Hilla is used -->
66+
<exclusion>
67+
<groupId>com.vaadin</groupId>
68+
<artifactId>hilla-dev</artifactId>
69+
</exclusion>
70+
<exclusion>
71+
<groupId>com.vaadin</groupId>
72+
<artifactId>copilot</artifactId>
73+
</exclusion>
74+
<!-- Lumo is used instead -->
75+
<exclusion>
76+
<groupId>com.vaadin</groupId>
77+
<artifactId>vaadin-material-theme</artifactId>
78+
</exclusion>
79+
<!-- React is not enabled and thus not required -->
80+
<exclusion>
81+
<groupId>com.vaadin</groupId>
82+
<artifactId>flow-react</artifactId>
83+
</exclusion>
84+
<!-- There is like 10 people on the planet that need this by default -->
85+
<exclusion>
86+
<groupId>com.vaadin</groupId>
87+
<artifactId>collaboration-engine</artifactId>
88+
</exclusion>
89+
<!-- No Wildfly used here -->
90+
<exclusion>
91+
<groupId>com.vaadin.servletdetector</groupId>
92+
<artifactId>throw-if-servlet3</artifactId>
93+
</exclusion>
94+
</exclusions>
95+
</dependency>
96+
97+
<!-- Spring -->
98+
<dependency>
99+
<groupId>com.vaadin</groupId>
100+
<artifactId>vaadin-spring-boot-starter</artifactId>
101+
<exclusions>
102+
<!-- No Hilla is used -->
103+
<exclusion>
104+
<groupId>com.vaadin</groupId>
105+
<artifactId>hilla</artifactId>
106+
</exclusion>
107+
</exclusions>
108+
</dependency>
109+
<!-- Temporarily excluded by Vaadin due to "security vulnerability" -->
110+
<dependency>
111+
<groupId>org.yaml</groupId>
112+
<artifactId>snakeyaml</artifactId>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.springframework.boot</groupId>
116+
<artifactId>spring-boot-devtools</artifactId>
117+
<optional>true</optional>
37118
</dependency>
38119
</dependencies>
39120

40121
<build>
41122
<finalName>${project.artifactId}</finalName>
42-
123+
124+
<pluginManagement>
125+
<plugins>
126+
<plugin>
127+
<groupId>org.springframework.boot</groupId>
128+
<artifactId>spring-boot-maven-plugin</artifactId>
129+
<version>${org.springframework.boot.version}</version>
130+
</plugin>
131+
</plugins>
132+
</pluginManagement>
133+
43134
<plugins>
135+
<plugin>
136+
<groupId>com.vaadin</groupId>
137+
<artifactId>vaadin-maven-plugin</artifactId>
138+
<version>${vaadin.version}</version>
139+
<executions>
140+
<execution>
141+
<goals>
142+
<goal>prepare-frontend</goal>
143+
</goals>
144+
</execution>
145+
</executions>
146+
<configuration>
147+
<!-- Can only be true if hilla is used -->
148+
<!-- Takes a few seconds to scan everything for hilla -->
149+
<frontendHotdeploy>false</frontendHotdeploy>
150+
<!-- Prevent scanning for react (not used) -->
151+
<reactEnable>false</reactEnable>
152+
</configuration>
153+
</plugin>
44154
<plugin>
45155
<groupId>org.apache.maven.plugins</groupId>
46156
<artifactId>maven-compiler-plugin</artifactId>
@@ -53,33 +163,104 @@
53163
</configuration>
54164
</plugin>
55165
<plugin>
56-
<groupId>org.apache.maven.plugins</groupId>
57-
<artifactId>maven-assembly-plugin</artifactId>
58-
<version>3.7.1</version>
59-
<configuration>
60-
<archive>
61-
<manifest>
62-
<mainClass>${mainClass}</mainClass>
63-
</manifest>
64-
<manifestEntries>
65-
<Multi-Release>true</Multi-Release>
66-
</manifestEntries>
67-
</archive>
68-
<descriptorRefs>
69-
<descriptorRef>jar-with-dependencies</descriptorRef>
70-
</descriptorRefs>
71-
<appendAssemblyId>false</appendAssemblyId>
72-
</configuration>
166+
<groupId>org.codehaus.mojo</groupId>
167+
<artifactId>exec-maven-plugin</artifactId>
168+
<version>3.5.1</version>
73169
<executions>
74170
<execution>
75-
<id>make-assembly</id> <!-- this is used for inheritance merges -->
76-
<phase>package</phase> <!-- bind to the packaging phase -->
171+
<id>patch-package-json-overrides</id>
172+
<phase>compile</phase>
77173
<goals>
78-
<goal>single</goal>
174+
<goal>java</goal>
79175
</goals>
176+
<configuration>
177+
<mainClass>software.xdev.vaadin.vpjo.Launcher</mainClass>
178+
<arguments>
179+
<argument>${project.basedir}</argument>
180+
<argument>${project.build.directory}</argument>
181+
</arguments>
182+
<includeProjectDependencies>false</includeProjectDependencies>
183+
<includePluginDependencies>true</includePluginDependencies>
184+
<executableDependency>
185+
<groupId>software.xdev</groupId>
186+
<artifactId>vaadin-package-json-optimizer</artifactId>
187+
</executableDependency>
188+
</configuration>
80189
</execution>
81190
</executions>
191+
<dependencies>
192+
<dependency>
193+
<groupId>software.xdev</groupId>
194+
<artifactId>vaadin-package-json-optimizer</artifactId>
195+
<version>${project.version}</version>
196+
</dependency>
197+
</dependencies>
82198
</plugin>
83199
</plugins>
84200
</build>
201+
202+
<profiles>
203+
<profile>
204+
<id>dev</id>
205+
<activation>
206+
<activeByDefault>true</activeByDefault>
207+
</activation>
208+
<dependencies>
209+
<dependency>
210+
<groupId>software.xdev</groupId>
211+
<artifactId>vaadin-package-json-optimizer</artifactId>
212+
<version>${project.version}</version>
213+
</dependency>
214+
</dependencies>
215+
</profile>
216+
<profile>
217+
<id>production</id>
218+
<dependencies>
219+
<!-- Exclude development dependencies from production -->
220+
<dependency>
221+
<groupId>com.vaadin</groupId>
222+
<artifactId>vaadin-core</artifactId>
223+
<exclusions>
224+
<exclusion>
225+
<groupId>com.vaadin</groupId>
226+
<artifactId>vaadin-dev</artifactId>
227+
</exclusion>
228+
</exclusions>
229+
</dependency>
230+
</dependencies>
231+
<build>
232+
<plugins>
233+
<plugin>
234+
<groupId>com.vaadin</groupId>
235+
<artifactId>vaadin-maven-plugin</artifactId>
236+
<version>${vaadin.version}</version>
237+
<executions>
238+
<execution>
239+
<goals>
240+
<goal>prepare-frontend</goal>
241+
<goal>build-frontend</goal>
242+
</goals>
243+
</execution>
244+
</executions>
245+
</plugin>
246+
<plugin>
247+
<groupId>org.springframework.boot</groupId>
248+
<artifactId>spring-boot-maven-plugin</artifactId>
249+
<configuration>
250+
<mainClass>${mainClass}</mainClass>
251+
</configuration>
252+
<executions>
253+
<execution>
254+
<id>repackage</id>
255+
<goals>
256+
<goal>repackage</goal>
257+
</goals>
258+
<phase>package</phase>
259+
</execution>
260+
</executions>
261+
</plugin>
262+
</plugins>
263+
</build>
264+
</profile>
265+
</profiles>
85266
</project>

0 commit comments

Comments
 (0)