diff --git a/.changeset/chilly-rules-dress.md b/.changeset/chilly-rules-dress.md new file mode 100644 index 000000000000..27edf70edad5 --- /dev/null +++ b/.changeset/chilly-rules-dress.md @@ -0,0 +1,6 @@ +--- +'@modern-js/server-core': patch +--- + +fix(server-core): support cjs async server loader entry +fix(server-core): 支持 cjs 类型的异步 server loader entry diff --git a/packages/cli/plugin-data-loader/src/cli/loader.ts b/packages/cli/plugin-data-loader/src/cli/loader.ts index e972b80612f8..c80cba6787fd 100644 --- a/packages/cli/plugin-data-loader/src/cli/loader.ts +++ b/packages/cli/plugin-data-loader/src/cli/loader.ts @@ -35,6 +35,13 @@ export default async function loader( return source; } + if ( + target === 'async-node' || + (Array.isArray(target) && target.includes('async-node')) + ) { + return source; + } + const { resourceQuery } = this; // parse options from resouceQuery const options = resourceQuery diff --git a/packages/server/core/src/adapters/node/plugins/resource.ts b/packages/server/core/src/adapters/node/plugins/resource.ts index d72c72a82703..298660258e30 100644 --- a/packages/server/core/src/adapters/node/plugins/resource.ts +++ b/packages/server/core/src/adapters/node/plugins/resource.ts @@ -52,7 +52,15 @@ export function injectTemplates( const dynamicImport = (filePath: string) => { try { const module = require(filePath); - return Promise.resolve(module); + if (module.default) { + return Promise.resolve(module.default); + } + return Promise.resolve(module).then(m => { + if (m.default) { + return m.default; + } + return m; + }); } catch (e) { return Promise.reject(e); }