@@ -5,22 +5,71 @@ import { resolve } from "path";
55const isWatch = process . argv . includes ( "--watch" ) ;
66
77async function build ( ) {
8- const result = await Bun . build ( {
8+ // Build main app
9+ const mainResult = await Bun . build ( {
910 entrypoints : [ "./src/browser/index.html" ] ,
1011 outdir : "./dist/browser" ,
1112 plugins : [ tailwind ] ,
13+ target : "browser" ,
14+ format : "esm" ,
1215 } ) ;
1316
14- if ( ! result . success ) {
15- console . error ( "Build failed:" ) ;
16- for ( const log of result . logs ) {
17+ if ( ! mainResult . success ) {
18+ console . error ( "Main build failed:" ) ;
19+ for ( const log of mainResult . logs ) {
1720 console . error ( log ) ;
1821 }
1922 return false ;
2023 }
2124
22- console . log ( `Bundled ${ result . outputs . length } files` ) ;
23- for ( const output of result . outputs ) {
25+ // Build worker separately with document shim for Prism/refractor
26+ const workerResult = await Bun . build ( {
27+ entrypoints : [ "./src/browser/lib/diff-worker.ts" ] ,
28+ outdir : "./dist/browser/lib" ,
29+ target : "browser" ,
30+ format : "esm" ,
31+ banner : `// Worker shim for libraries that check for document (Prism/refractor)
32+ if (typeof document === 'undefined') {
33+ globalThis.document = {
34+ currentScript: null,
35+ querySelectorAll: () => [],
36+ querySelector: () => null,
37+ getElementById: () => null,
38+ getElementsByClassName: () => [],
39+ getElementsByTagName: () => [],
40+ createElement: () => ({
41+ setAttribute: () => {},
42+ getAttribute: () => null,
43+ appendChild: () => {},
44+ removeChild: () => {},
45+ classList: { add: () => {}, remove: () => {}, contains: () => false },
46+ style: {},
47+ innerHTML: '',
48+ textContent: '',
49+ }),
50+ createTextNode: () => ({ textContent: '' }),
51+ createDocumentFragment: () => ({ appendChild: () => {}, childNodes: [] }),
52+ head: { appendChild: () => {}, removeChild: () => {} },
53+ body: { appendChild: () => {}, removeChild: () => {} },
54+ addEventListener: () => {},
55+ removeEventListener: () => {},
56+ };
57+ }
58+ ` ,
59+ } ) ;
60+
61+ if ( ! workerResult . success ) {
62+ console . error ( "Worker build failed:" ) ;
63+ for ( const log of workerResult . logs ) {
64+ console . error ( log ) ;
65+ }
66+ return false ;
67+ }
68+
69+ const allOutputs = [ ...mainResult . outputs , ...workerResult . outputs ] ;
70+
71+ console . log ( `Bundled ${ allOutputs . length } files` ) ;
72+ for ( const output of allOutputs ) {
2473 console . log ( ` ${ output . path } ` ) ;
2574 }
2675 return true ;
0 commit comments