|
1 | 1 | import { pathToFileURL } from 'url'; |
2 | 2 | import { LoaderDefinition } from 'webpack'; |
3 | 3 |
|
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; |
7 | 7 |
|
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 | + const result = await load(fileUrl, null, async () => ({ |
| 16 | + format: 'module', |
| 17 | + source, |
| 18 | + })); |
| 19 | + return result.source; |
27 | 20 | }; |
28 | 21 |
|
29 | 22 | export default RSCWebpackLoader; |
0 commit comments