Skip to content

Commit 229fe5f

Browse files
committed
feat: Create a Vite plugin that injects sentryConfig into the global config
1 parent b7c095b commit 229fe5f

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { sentryReactRouter } from './plugin';
22
export { sentryOnBuildEnd } from './buildEnd/handleOnBuildEnd';
33
export type { SentryReactRouterBuildOptions } from './types';
4+
export { makeConfigInjectorPlugin } from './makeConfigInjectorPlugin';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { type Plugin } from 'vite';
2+
import type { SentryReactRouterBuildOptions } from './types';
3+
4+
/**
5+
* Creates a Vite plugin that injects the Sentry options into the global Vite config.
6+
* This ensures the sentryConfig is available to other components that need access to it,
7+
* like the buildEnd hook.
8+
*
9+
* @param options - Configuration options for the Sentry Vite plugin
10+
* @returns A Vite plugin that injects sentryConfig into the global config
11+
*/
12+
export function makeConfigInjectorPlugin(options: SentryReactRouterBuildOptions): Plugin {
13+
return {
14+
name: 'sentry-react-router-config-injector',
15+
enforce: 'pre',
16+
config(config) {
17+
return {
18+
...config,
19+
sentryConfig: options,
20+
};
21+
},
22+
};
23+
}

packages/react-router/src/vite/plugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type Plugin } from 'vite';
33
import { makeCustomSentryVitePlugins } from './makeCustomSentryVitePlugins';
44
import { makeEnableSourceMapsPlugin } from './makeEnableSourceMapsPlugin';
55
import type { SentryReactRouterBuildOptions } from './types';
6+
import { makeConfigInjectorPlugin } from './makeConfigInjectorPlugin';
67

78
/**
89
* A Vite plugin for Sentry that handles source map uploads and bundle size optimizations.
@@ -17,6 +18,8 @@ export async function sentryReactRouter(
1718
): Promise<Plugin[]> {
1819
const plugins: Plugin[] = [];
1920

21+
plugins.push(makeConfigInjectorPlugin(options));
22+
2023
if (process.env.NODE_ENV !== 'development' && config.command === 'build' && config.mode !== 'development') {
2124
plugins.push(makeEnableSourceMapsPlugin(options));
2225
plugins.push(...(await makeCustomSentryVitePlugins(options)));

0 commit comments

Comments
 (0)