1
1
import type { Nuxt } from '@nuxt/schema' ;
2
- import { sentryRollupPlugin } from '@sentry/rollup-plugin' ;
3
- import { sentryVitePlugin } from '@sentry/vite-plugin' ;
2
+ import { type SentryRollupPluginOptions , sentryRollupPlugin } from '@sentry/rollup-plugin' ;
3
+ import { type SentryVitePluginOptions , sentryVitePlugin } from '@sentry/vite-plugin' ;
4
4
import type { NitroConfig } from 'nitropack' ;
5
5
import type { SentryNuxtModuleOptions } from '../common/types' ;
6
6
7
7
/**
8
- * Setup source maps for Sentry inside the Nuxt module during build time.
8
+ * Setup source maps for Sentry inside the Nuxt module during build time (in Vite for Nuxt and Rollup for Nitro) .
9
9
*/
10
10
export function setupSourceMaps ( moduleOptions : SentryNuxtModuleOptions , nuxt : Nuxt ) : void {
11
11
const sourceMapsUploadOptions = moduleOptions . sourceMapsUploadOptions || { } ;
12
12
const sourceMapsEnabled = sourceMapsUploadOptions . enabled ?? true ;
13
13
14
14
nuxt . hook ( 'vite:extendConfig' , async ( viteInlineConfig , _env ) => {
15
15
if ( sourceMapsEnabled && viteInlineConfig . mode !== 'development' ) {
16
- const sentryPlugin = sentryVitePlugin ( getPluginOptions ( moduleOptions ) ) ;
17
-
18
16
// Add Sentry plugin
19
17
viteInlineConfig . plugins = viteInlineConfig . plugins || [ ] ;
20
- viteInlineConfig . plugins . push ( sentryPlugin ) ;
18
+ viteInlineConfig . plugins . push ( sentryVitePlugin ( getPluginOptions ( moduleOptions ) ) ) ;
21
19
22
20
// Enable source maps
23
21
viteInlineConfig . build = viteInlineConfig . build || { } ;
@@ -29,14 +27,13 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
29
27
30
28
nuxt . hook ( 'nitro:config' , ( nitroConfig : NitroConfig ) => {
31
29
if ( sourceMapsEnabled && ! nitroConfig . dev ) {
32
- const sentryPlugin = sentryRollupPlugin ( getPluginOptions ( moduleOptions ) ) ;
33
-
34
30
if ( nitroConfig . rollupConfig ) {
35
31
// Add Sentry plugin
36
32
if ( ! Array . isArray ( nitroConfig . rollupConfig . plugins ) ) {
37
33
nitroConfig . rollupConfig . plugins = nitroConfig . rollupConfig . plugins ? [ nitroConfig . rollupConfig . plugins ] : [ ] ;
38
34
}
39
- nitroConfig . rollupConfig . plugins . push ( sentryPlugin ) ;
35
+
36
+ nitroConfig . rollupConfig . plugins . push ( sentryRollupPlugin ( getPluginOptions ( moduleOptions ) ) ) ;
40
37
41
38
// Enable source maps
42
39
nitroConfig . rollupConfig . output = nitroConfig ?. rollupConfig ?. output || { } ;
@@ -56,7 +53,7 @@ function normalizePath(path: string): string {
56
53
return path . replace ( / ^ ( \. \. \/ ) + / , './' ) ;
57
54
}
58
55
59
- function getPluginOptions ( moduleOptions : SentryNuxtModuleOptions ) : object {
56
+ function getPluginOptions ( moduleOptions : SentryNuxtModuleOptions ) : SentryVitePluginOptions | SentryRollupPluginOptions {
60
57
const sourceMapsUploadOptions = moduleOptions . sourceMapsUploadOptions || { } ;
61
58
62
59
return {
0 commit comments