From a23d76d6d3eca93d420a362f7591498e3d6b39ee Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 15 May 2023 06:37:41 +0300 Subject: [PATCH] feat: Include bundle size visualization for production build (#16781) --- .../flow/server/frontend/dependencies/vite/package.json | 1 + flow-server/src/main/resources/vite.generated.ts | 6 +++++- .../com/vaadin/flow/server/frontend/NodeUpdaterTest.java | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/flow-server/src/main/resources/com/vaadin/flow/server/frontend/dependencies/vite/package.json b/flow-server/src/main/resources/com/vaadin/flow/server/frontend/dependencies/vite/package.json index 8f27a7afe7e..6f2f3984a1e 100644 --- a/flow-server/src/main/resources/com/vaadin/flow/server/frontend/dependencies/vite/package.json +++ b/flow-server/src/main/resources/com/vaadin/flow/server/frontend/dependencies/vite/package.json @@ -13,6 +13,7 @@ "vite": "4.3.5", "@rollup/plugin-replace": "5.0.2", "@rollup/pluginutils": "5.0.2", + "rollup-plugin-visualizer": "5.9.0", "rollup-plugin-brotli": "3.1.0", "vite-plugin-checker": "0.5.5", "mkdirp": "1.0.4", diff --git a/flow-server/src/main/resources/vite.generated.ts b/flow-server/src/main/resources/vite.generated.ts index 31b784246dc..3580a566ab8 100644 --- a/flow-server/src/main/resources/vite.generated.ts +++ b/flow-server/src/main/resources/vite.generated.ts @@ -32,6 +32,8 @@ import postcssLit from '#buildFolder#/plugins/rollup-plugin-postcss-lit-custom/r import { createRequire } from 'module'; +import { visualizer } from 'rollup-plugin-visualizer'; + // Make `require` compatible with ES modules const require = createRequire(import.meta.url); @@ -49,6 +51,7 @@ const projectPackageJsonFile = path.resolve(__dirname, 'package.json'); const buildOutputFolder = devBundle ? devBundleFolder : frontendBundleFolder; const statsFolder = path.resolve(__dirname, devBundle ? settings.devBundleStatsOutput : settings.statsOutput); const statsFile = path.resolve(statsFolder, 'stats.json'); +const bundleSizeFile = path.resolve(statsFolder, 'bundle-size.html'); const nodeModulesFolder = path.resolve(__dirname, 'node_modules'); const webComponentTags = '#webComponentTags#'; @@ -773,7 +776,8 @@ export const vaadinConfig: UserConfigFn = (env) => { }, checker({ typescript: true - }) + }), + !devMode && visualizer({ brotliSize: true, filename: bundleSizeFile }) ] }; }; diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeUpdaterTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeUpdaterTest.java index ed5151f6ce5..f466fb63e9c 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeUpdaterTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/NodeUpdaterTest.java @@ -132,6 +132,7 @@ public void getDefaultDevDependencies_includesAllDependencies_whenUsingVite() { expectedDependencies.add("rollup-plugin-brotli"); expectedDependencies.add("@rollup/plugin-replace"); expectedDependencies.add("@rollup/pluginutils"); + expectedDependencies.add("rollup-plugin-visualizer"); expectedDependencies.add("vite-plugin-checker"); expectedDependencies.add("mkdirp"); expectedDependencies.add("workbox-build");