Skip to content

Commit

Permalink
ref: Optimize build configs and builds (#480)
Browse files Browse the repository at this point in the history
This change mainly removes the enforcement of `process.env.NODE_ENV ===
'development'` for Spotlight which in turn also enables significant
bundle size savings as we include the React library which does
optimizations based on this value.

Without the patch:

File | Size | Gzipped | Map
---- | ---- | ------- | ---
dist/sentry-spotlight.js | 0.65 kB | 0.39 kB | 0.10 kB
dist/main-f821b601.js | 163.24 kB | 38.35 kB | 267.29 kB
dist/index-122c6ab6.js | 1,472.54 kB | 455.16 kB | 3,871.30 kB
dist/sentry-spotlight.iife.js | 1,206.02 kB | 437.51 kB | 4,010.64 kB

With the patch:

File | Size | Gzipped | Map
-----|------|---------|----
dist/sentry-spotlight.js   |   0.65 kB |   0.39 kB |     0.10 kB
dist/main-02efbde8.js    |   163.24 kB |  38.35 kB |   267.29 kB
dist/index-8591b57c.js  |  1,181.10 kB | 384.51 kB | 2,516.24 kB
dist/sentry-spotlight.iife.js | 1,016.89 kB | 380.25 kB | 2,679.17 kB
  • Loading branch information
BYK committed Aug 9, 2024
1 parent 16704fe commit e5b84d2
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 22 deletions.
10 changes: 4 additions & 6 deletions e2e-tests/nextjs/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ Sentry.init({
],
});

if (process.env.NODE_ENV === 'development') {
Spotlight.init({
debug: true,
integrations: [customIntegration()],
});
}
Spotlight.init({
debug: true,
integrations: [customIntegration()],
});
2 changes: 1 addition & 1 deletion e2e-tests/nextjs/sentry.edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Sentry.init({

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
spotlight: process.env.NODE_ENV === 'development',
spotlight: true,
});
2 changes: 1 addition & 1 deletion e2e-tests/nextjs/sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Sentry.init({

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
spotlight: process.env.NODE_ENV === 'development',
spotlight: true,
});
4 changes: 1 addition & 3 deletions packages/overlay/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export default defineConfig({
removeReactDevToolsMessagePlugin(),
],
define: {
'process.env.NODE_ENV': "'development'",
'process.env.JEST_WORKER_ID': 1,
process: {},
'process.env.NODE_ENV': "'production'",
},
resolve: {
alias: {
Expand Down
3 changes: 1 addition & 2 deletions packages/overlay/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="vitest" />

// import tsconfigPaths from "vite-tsconfig-paths";
import { resolve } from 'path';
import { resolve } from 'node:path';
import { defineConfig } from 'vitest/config';

export default defineConfig({
Expand All @@ -12,7 +12,6 @@ export default defineConfig({
reporter: ['json'],
},
globals: true,
// setupFiles: ["./src/test/setup-test-env.ts"],
include: ['./test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
watchExclude: ['.*\\/node_modules\\/.*', '.*\\/dist\\/.*'],
},
Expand Down
5 changes: 0 additions & 5 deletions packages/sidecar/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const dependencies = Object.keys({
...packageJson.devDependencies,
});

const noExternal = process.env.NODE_ENV === 'production' ? dependencies : [];

export default defineConfig({
build: {
ssr: './src/main.ts',
Expand All @@ -19,7 +17,4 @@ export default defineConfig({
external: [...dependencies, ...builtinModules.map(x => `node:${x}`)],
},
},
ssr: {
noExternal,
},
});
2 changes: 1 addition & 1 deletion packages/spotlight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This package combines the Overlay from `@spotlightjs/overlay` and the sidecar from `@spotlightjs/sidecar`.

This means, you only need to install one package and you get everything required for spotlight. Nice!
This means, you only need to install one package and you get everything required for Spotlight. Neat!
2 changes: 0 additions & 2 deletions packages/spotlight/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export default defineConfig({
sidecar: resolve(__dirname, 'src/sidecar.ts'),
'vite-plugin': resolve(__dirname, 'src/vite-plugin.ts'),
},
// the proper extensions will be added
// fileName: 'sentry-spotlight',
},
rollupOptions: {
external: [...dependencies, ...builtinModules.map(x => `node:${x}`)],
Expand Down
2 changes: 1 addition & 1 deletion packages/spotlight/vite.overlay.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';

export default defineConfig({
Expand Down

0 comments on commit e5b84d2

Please sign in to comment.