Skip to content

Commit 479b4c4

Browse files
committed
Simplify RSCWebpackLoader
1 parent 6307be9 commit 479b4c4

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
import { pathToFileURL } from 'url';
22
import { LoaderDefinition } from 'webpack';
33

4-
const RSCWebpackLoader: LoaderDefinition = function RSCWebpackLoader(source, sourceMap) {
5-
// Mark loader as async since we're doing async operations
6-
const callback = this.async();
4+
const RSCWebpackLoader: LoaderDefinition = async function RSCWebpackLoader(source) {
5+
// Convert file path to URL format
6+
const fileUrl = pathToFileURL(this.resourcePath).href;
77

8-
(async () => {
9-
// Convert file path to URL format
10-
const fileUrl = pathToFileURL(this.resourcePath).href;
11-
12-
// Workaround for TS transpiling `await import` while we need to keep it.
13-
// See https://github.com/microsoft/TypeScript/issues/43329#issuecomment-1008361973
14-
// If we end up needing it more than once, prefer creating a non-compiled
15-
// `dynamicImport.js` file instead.
16-
// eslint-disable-next-line no-new-func
17-
const { load } = await new Function('return import("react-server-dom-webpack/node-loader")')() as
18-
typeof import('react-server-dom-webpack/node-loader');
19-
return load(fileUrl, null, async () => ({
20-
format: 'module',
21-
source,
22-
}));
23-
})().then(
24-
result => callback(null, result.source, sourceMap),
25-
error => callback(error),
26-
);
8+
// Workaround for TS transpiling `await import` while we need to keep it.
9+
// See https://github.com/microsoft/TypeScript/issues/43329#issuecomment-1008361973
10+
// If we end up needing it more than once, prefer creating a non-compiled
11+
// `dynamicImport.js` file instead.
12+
// eslint-disable-next-line no-new-func
13+
const { load } = await new Function('return import("react-server-dom-webpack/node-loader")')() as
14+
typeof import('react-server-dom-webpack/node-loader');
15+
return load(fileUrl, null, async () => ({
16+
format: 'module',
17+
source,
18+
}));
2719
};
2820

2921
export default RSCWebpackLoader;

0 commit comments

Comments
 (0)