@@ -7,6 +7,12 @@ import { rollup } from 'rollup';
77
88import { LoaderThis } from './types' ;
99
10+ const apiWrapperTemplatePath = path . resolve ( __dirname , '..' , 'templates' , 'apiWrapperTemplate.js' ) ;
11+ const apiWrapperTemplateCode = fs . readFileSync ( apiWrapperTemplatePath , { encoding : 'utf8' } ) ;
12+
13+ const pageWrapperTemplatePath = path . resolve ( __dirname , '..' , 'templates' , 'pageWrapperTemplate.js' ) ;
14+ const pageWrapperTemplateCode = fs . readFileSync ( pageWrapperTemplatePath , { encoding : 'utf8' } ) ;
15+
1016// Just a simple placeholder to make referencing module consistent
1117const SENTRY_WRAPPER_MODULE_NAME = 'sentry-wrapper-module' ;
1218
@@ -53,12 +59,7 @@ export default async function wrappingLoader(this: LoaderThis<LoaderOptions>, us
5359 return userCode ;
5460 }
5561
56- const templateFile = parameterizedRoute . startsWith ( '/api' ) ? 'apiWrapperTemplate.js' : 'pageWrapperTemplate.js' ;
57- const templatePath = path . resolve ( __dirname , `../templates/${ templateFile } ` ) ;
58- let templateCode = fs . readFileSync ( templatePath , { encoding : 'utf8' } ) ;
59-
60- // Make sure the template is included when running `webpack watch`
61- this . addDependency ( templatePath ) ;
62+ let templateCode = parameterizedRoute . startsWith ( '/api' ) ? apiWrapperTemplateCode : pageWrapperTemplateCode ;
6263
6364 // Inject the route and the path to the file we're wrapping into the template
6465 templateCode = templateCode . replace ( / _ _ R O U T E _ _ / g, parameterizedRoute . replace ( / \\ / g, '\\\\' ) ) ;
0 commit comments