|
1 | 1 | import * as esbuild from 'esbuild' |
2 | | -import { cpSync, mkdirSync, readdirSync } from 'fs' |
| 2 | +import { cpSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs' |
| 3 | +import { join } from 'path' |
3 | 4 | import { execSync } from 'child_process' |
4 | 5 |
|
5 | 6 | const dev = process.argv.includes('--watch') |
@@ -100,6 +101,16 @@ function brotliCompress() { |
100 | 101 | function copyPlatformScripts() { |
101 | 102 | mkdirSync(`${OUT}/platform`, { recursive: true }) |
102 | 103 | cpSync('src/platform', `${OUT}/platform`, { recursive: true }) |
| 104 | + // In src/, `../_hyperscript.js` resolves to the ESM source entry. |
| 105 | + // In dist/, the equivalent ESM bundle is `_hyperscript.esm.js` — `_hyperscript.js` |
| 106 | + // is the IIFE build and has no exports. Rewrite the import path on copy. |
| 107 | + for (const name of readdirSync(`${OUT}/platform`)) { |
| 108 | + if (!name.endsWith('.js')) continue |
| 109 | + const p = join(OUT, 'platform', name) |
| 110 | + const src = readFileSync(p, 'utf8') |
| 111 | + const fixed = src.replaceAll("'../_hyperscript.js'", "'../_hyperscript.esm.js'") |
| 112 | + if (fixed !== src) writeFileSync(p, fixed) |
| 113 | + } |
103 | 114 | } |
104 | 115 |
|
105 | 116 | if (dev) { |
|
0 commit comments