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
5 changes: 4 additions & 1 deletion e2e/cases/server/ssr/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspector from 'node:inspector';
import {
defineConfig,
logger,
Expand Down Expand Up @@ -25,6 +26,8 @@ export const serverRender =
export default defineConfig({
plugins: [pluginReact()],
dev: {
// enable writeToDisk to make sure the sourcemap files are generated on disk for debugging
writeToDisk: inspector.url() !== undefined,
Comment thread
9aoy marked this conversation as resolved.
setupMiddlewares: ({ unshift }, context) => {
const serverRenderMiddleware = serverRender(context);

Expand Down Expand Up @@ -53,7 +56,7 @@ export default defineConfig({
},
node: {
output: {
module: true,
module: process.env.TEST_ESM_LIBRARY === 'true',
target: 'node',
},
source: {
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/server/runner/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export class CommonJsRunner extends BasicRunner {

const args = Object.keys(currentModuleScope);
const argValues = args.map((arg) => currentModuleScope[arg]);
const code = `(function(${args.join(', ')}) {
${file.content}
})`;

const codeDefinition = `(function(${args.join(', ')}) {`;
const code = `${codeDefinition}${file.content}\n})`;

this.preExecute(code, file);
const dynamicImport = new Function(
Expand All @@ -122,6 +122,8 @@ export class CommonJsRunner extends BasicRunner {
// Runs the compiled code contained by the `vm.Script` within the context of the current `global` object.
const fn = vm.runInThisContext(code, {
filename: file.path,
lineOffset: 0,
Comment thread
chenjiahan marked this conversation as resolved.
columnOffset: -codeDefinition.length,
// Specify how the modules should be loaded during the evaluation of this script when `import()` is called.
importModuleDynamically: async (specifier) => {
const result = await dynamicImport(specifier);
Expand Down
Loading