From 424abe722e5b2c3d72ce60a3b2cb7b67ddc475b6 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Wed, 26 Apr 2023 14:06:05 +0200 Subject: [PATCH] Fix CJS being injected in ESM files Fix #2735 --- webpack-plugin/src/loaders/include.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webpack-plugin/src/loaders/include.ts b/webpack-plugin/src/loaders/include.ts index f8705471..4bebcce9 100644 --- a/webpack-plugin/src/loaders/include.ts +++ b/webpack-plugin/src/loaders/include.ts @@ -30,8 +30,12 @@ export const pitch: PitchLoaderDefinitionFunction = 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'); };