Fix CJS being injected in ESM files

Fix #2735
This commit is contained in:
Titouan Mathis 2023-04-26 14:06:05 +02:00 committed by GitHub
parent b61f404730
commit 424abe722e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,8 +30,12 @@ export const pitch: PitchLoaderDefinitionFunction<ILoaderOptions> = function pit
...(globals
? Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`)
: []),
...pre.map((include: any) => `require(${stringifyRequest(include)});`),
`module.exports = require(${stringifyRequest(`!!${remainingRequest}`)});`,
...post.map((include: any) => `require(${stringifyRequest(include)});`)
...pre.map((include: any) => `import ${stringifyRequest(include)};`),
`
import * as monaco from ${stringifyRequest(`!!${remainingRequest}`)};
export * from ${stringifyRequest(`!!${remainingRequest}`)};
export default monaco;
`,
...post.map((include: any) => `import ${stringifyRequest(include)};`)
].join('\n');
};