Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ export function constructWebpackConfigFunction(
buildContext: BuildContext,
): WebpackConfigObject {
const { isServer, dev: isDev, dir: projectDir } = buildContext;
const webpackPluginOptions = getWebpackPluginOptions(
buildContext,
userSentryWebpackPluginOptions,
userSentryOptions,
);

let rawNewConfig = { ...incomingConfig };

Expand All @@ -88,7 +83,7 @@ export function constructWebpackConfigFunction(
const newConfig = setUpModuleRules(rawNewConfig);

// Add a loader which will inject code that sets global values
addValueInjectionLoader(newConfig, userNextConfig, userSentryOptions, webpackPluginOptions);
addValueInjectionLoader(newConfig, userNextConfig, userSentryOptions);

if (isServer) {
if (userSentryOptions.autoInstrumentServerFunctions !== false) {
Expand Down Expand Up @@ -200,7 +195,11 @@ export function constructWebpackConfigFunction(
}

newConfig.plugins = newConfig.plugins || [];
newConfig.plugins.push(new SentryWebpackPlugin(webpackPluginOptions));
newConfig.plugins.push(
new SentryWebpackPlugin(
getWebpackPluginOptions(buildContext, userSentryWebpackPluginOptions, userSentryOptions),
),
);
}

return newConfig;
Expand Down Expand Up @@ -529,9 +528,8 @@ export function getWebpackPluginOptions(
configFile: hasSentryProperties ? 'sentry.properties' : undefined,
stripPrefix: ['webpack://_N_E/'],
urlPrefix,
// We don't want to inject the release using the webpack plugin because we're instead doing it via the prefix loader
// combined with the release prefix loader template.
entries: [],
entries: (entryPointName: string) =>
shouldAddSentryToEntryPoint(entryPointName, isServer, userSentryOptions.excludeServerRoutes, isDev),
release: getSentryRelease(buildId),
dryRun: isDev,
});
Expand Down Expand Up @@ -655,32 +653,10 @@ function addValueInjectionLoader(
newConfig: WebpackConfigObjectWithModuleRules,
userNextConfig: NextConfigObject,
userSentryOptions: UserSentryOptions,
webpackPluginOptions: SentryWebpackPlugin.SentryCliPluginOptions,
): void {
const assetPrefix = userNextConfig.assetPrefix || userNextConfig.basePath || '';
const releaseValue = webpackPluginOptions.release || process.env.SENTRY_RELEASE;
const orgValue = webpackPluginOptions.org || process.env.SENTRY_ORG;
const projectValue = webpackPluginOptions.project || process.env.SENTRY_PROJECT;

const isomorphicValues = {
// Inject release into SDK
...(releaseValue
? {
SENTRY_RELEASE: {
id: releaseValue,
},
}
: undefined),

// Enable module federation support (see https://github.com/getsentry/sentry-webpack-plugin/pull/307)
...(projectValue && releaseValue
? {
SENTRY_RELEASES: {
[orgValue ? `${projectValue}@${orgValue}` : projectValue]: { id: releaseValue },
},
}
: undefined),

// `rewritesTunnel` set by the user in Next.js config
__sentryRewritesTunnelPath__: userSentryOptions.tunnelRoute,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Sentry webpack plugin config', () => {
authToken: 'dogsarebadatkeepingsecrets', // picked up from env
stripPrefix: ['webpack://_N_E/'], // default
urlPrefix: '~/_next', // default
entries: [], // default, tested separately elsewhere
entries: expect.any(Function), // default, tested separately elsewhere
release: 'doGsaREgReaT', // picked up from env
dryRun: false, // based on buildContext.dev being false
}),
Expand Down