Skip to content

Commit 7af6c7b

Browse files
author
Luca Forstner
committed
Extract template reading out of loader
1 parent 0ec7960 commit 7af6c7b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/nextjs/src/config/loaders/wrappingLoader.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { rollup } from 'rollup';
77

88
import { 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
1117
const 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(/__ROUTE__/g, parameterizedRoute.replace(/\\/g, '\\\\'));

0 commit comments

Comments
 (0)