Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix(server-core): support cjs async server loader entry #5998

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changeset/chilly-rules-dress.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions packages/cli/plugin-data-loader/src/cli/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion packages/server/core/src/adapters/node/plugins/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading