forked from getsentry/sentry-javascript-bundler-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
65 lines (58 loc) · 2.26 KB
/
index.ts
File metadata and controls
65 lines (58 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
sentryUnpluginFactory,
Options,
createRollupInjectionHooks,
createRollupDebugIdUploadHooks,
SentrySDKBuildFlags,
createRollupBundleSizeOptimizationHooks,
createComponentNameAnnotateHooks,
Logger,
} from "@sentry/bundler-plugin-core";
import { UnpluginOptions, VitePlugin } from "unplugin";
function viteInjectionPlugin(injectionCode: string, debugIds: boolean): UnpluginOptions {
return {
name: "sentry-vite-release-injection-plugin",
// run `post` to avoid tripping up @rollup/plugin-commonjs when cjs is used
// as we inject an `import` statement
enforce: "post" as const, // need this so that vite runs the resolveId hook
vite: createRollupInjectionHooks(injectionCode, debugIds),
};
}
function viteComponentNameAnnotatePlugin(ignoredComponents?: string[]): UnpluginOptions {
return {
name: "sentry-vite-component-name-annotate-plugin",
enforce: "pre" as const,
vite: createComponentNameAnnotateHooks(ignoredComponents),
};
}
function viteDebugIdUploadPlugin(
upload: (buildArtifacts: string[]) => Promise<void>,
logger: Logger,
createDependencyOnBuildArtifacts: () => () => void
): UnpluginOptions {
return {
name: "sentry-vite-debug-id-upload-plugin",
vite: createRollupDebugIdUploadHooks(upload, logger, createDependencyOnBuildArtifacts),
};
}
function viteBundleSizeOptimizationsPlugin(
replacementValues: SentrySDKBuildFlags
): UnpluginOptions {
return {
name: "sentry-vite-bundle-size-optimizations-plugin",
vite: createRollupBundleSizeOptimizationHooks(replacementValues),
};
}
const sentryUnplugin = sentryUnpluginFactory({
injectionPlugin: viteInjectionPlugin,
componentNameAnnotatePlugin: viteComponentNameAnnotatePlugin,
debugIdUploadPlugin: viteDebugIdUploadPlugin,
bundleSizeOptimizationsPlugin: viteBundleSizeOptimizationsPlugin,
});
export const sentryVitePlugin = (options?: Options): VitePlugin[] => {
const result = sentryUnplugin.vite(options);
// unplugin returns a single plugin instead of an array when only one plugin is created, so we normalize this here.
return Array.isArray(result) ? result : [result];
};
export type { Options as SentryVitePluginOptions } from "@sentry/bundler-plugin-core";
export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";