@@ -4,7 +4,6 @@ import * as SentryWebpackPlugin from '@sentry/webpack-plugin';
4
4
5
5
import {
6
6
BuildContext ,
7
- EntryPointObject ,
8
7
EntryPointValue ,
9
8
EntryPropertyObject ,
10
9
NextConfigObject ,
@@ -13,7 +12,6 @@ import {
13
12
WebpackConfigObject ,
14
13
WebpackEntryProperty ,
15
14
} from './types' ;
16
- import { SERVER_SDK_INIT_PATH , storeServerConfigFileLocation } from './utils' ;
17
15
18
16
export { SentryWebpackPlugin } ;
19
17
@@ -58,12 +56,6 @@ export function constructWebpackConfigFunction(
58
56
const newWebpackFunction = ( incomingConfig : WebpackConfigObject , buildContext : BuildContext ) : WebpackConfigObject => {
59
57
let newConfig = { ...incomingConfig } ;
60
58
61
- // if we're building server code, store the webpack output path as an env variable, so we know where to look for the
62
- // webpack-processed version of `sentry.server.config.js` when we need it
63
- if ( newConfig . target === 'node' ) {
64
- storeServerConfigFileLocation ( newConfig ) ;
65
- }
66
-
67
59
// if user has custom webpack config (which always takes the form of a function), run it so we have actual values to
68
60
// work with
69
61
if ( 'webpack' in userNextConfig && typeof userNextConfig . webpack === 'function' ) {
@@ -140,39 +132,11 @@ async function addSentryToEntryProperty(
140
132
const newEntryProperty =
141
133
typeof currentEntryProperty === 'function' ? await currentEntryProperty ( ) : { ...currentEntryProperty } ;
142
134
143
- // Add a new element to the `entry` array, we force webpack to create a bundle out of the user's
144
- // `sentry.server.config.js` file and output it to `SERVER_INIT_LOCATION`. (See
145
- // https://webpack.js.org/guides/code-splitting/#entry-points.) We do this so that the user's config file is run
146
- // through babel (and any other processors through which next runs the rest of the user-provided code - pages, API
147
- // routes, etc.). Specifically, we need any ESM-style `import` code to get transpiled into ES5, so that we can call
148
- // `require()` on the resulting file when we're instrumenting the sesrver. (We can't use a dynamic import there
149
- // because that then forces the user into a particular TS config.)
150
-
151
- // On the server, create a separate bundle, as there's no one entry point depended on by all the others
152
- if ( buildContext . isServer ) {
153
- // slice off the final `.js` since webpack is going to add it back in for us, and we don't want to end up with
154
- // `.js.js` as the extension
155
- newEntryProperty [ SERVER_SDK_INIT_PATH . slice ( 0 , - 3 ) ] = SERVER_SDK_CONFIG_FILE ;
156
- }
157
- // On the client, it's sufficient to inject it into the `main` JS code, which is included in every browser page.
158
- else {
159
- addFileToExistingEntryPoint ( newEntryProperty , 'main' , CLIENT_SDK_CONFIG_FILE ) ;
160
-
161
- // To work around a bug in nextjs, we need to ensure that the `main.js` entry is empty (otherwise it'll choose that
162
- // over `main` and we'll lose the change we just made). In case some other library has put something into it, copy
163
- // its contents over before emptying it out. See
164
- // https://github.com/getsentry/sentry-javascript/pull/3696#issuecomment-863363803.)
165
- const mainjsValue = newEntryProperty [ 'main.js' ] ;
166
- if ( Array . isArray ( mainjsValue ) && mainjsValue . length > 0 ) {
167
- const mainValue = newEntryProperty . main ;
168
-
169
- // copy the `main.js` entries over
170
- newEntryProperty . main = Array . isArray ( mainValue )
171
- ? [ ...mainjsValue , ...mainValue ]
172
- : { ...( mainValue as EntryPointObject ) , import : [ ...mainjsValue , ...( mainValue as EntryPointObject ) . import ] } ;
173
-
174
- // nuke the entries
175
- newEntryProperty [ 'main.js' ] = [ ] ;
135
+ const userConfigFile = buildContext . isServer ? SERVER_SDK_CONFIG_FILE : CLIENT_SDK_CONFIG_FILE ;
136
+
137
+ for ( const entryPointName in newEntryProperty ) {
138
+ if ( entryPointName === 'pages/_app' || entryPointName . includes ( 'pages/api' ) ) {
139
+ addFileToExistingEntryPoint ( newEntryProperty , entryPointName , userConfigFile ) ;
176
140
}
177
141
}
178
142
0 commit comments