@@ -7,6 +7,12 @@ import { rollup } from 'rollup';
7
7
8
8
import { LoaderThis } from './types' ;
9
9
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
+
10
16
// Just a simple placeholder to make referencing module consistent
11
17
const SENTRY_WRAPPER_MODULE_NAME = 'sentry-wrapper-module' ;
12
18
@@ -53,12 +59,7 @@ export default async function wrappingLoader(this: LoaderThis<LoaderOptions>, us
53
59
return userCode ;
54
60
}
55
61
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 ;
62
63
63
64
// Inject the route and the path to the file we're wrapping into the template
64
65
templateCode = templateCode . replace ( / _ _ R O U T E _ _ / g, parameterizedRoute . replace ( / \\ / g, '\\\\' ) ) ;
0 commit comments