Skip to content

Commit

Permalink
Build: Shim CJS-only globals in ESM output
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Sep 19, 2024
1 parent 57ee6e1 commit 6bbffdf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/prepare/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
silent: true,
treeshake: true,
entry: nonPresetEntries,
...(platform === 'node' && {
banner: {
js: dedent`
import ESM_COMPAT_Module from "node:module";
import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url';
import { dirname as ESM_COMPAT_dirname } from 'node:path';
const __filename = ESM_COMPAT_fileURLToPath(import.meta.url);
const __dirname = ESM_COMPAT_dirname(__filename);
const require = ESM_COMPAT_Module.createRequire(import.meta.url);
`,
},
}),
shims: false,
watch,
outDir,
Expand Down

0 comments on commit 6bbffdf

Please sign in to comment.