@@ -27,15 +27,32 @@ const externalVSCodePlugin = {
2727 }
2828}
2929
30- // Plugin to mark React output imports as external during DTS generation
31- // This prevents tsup from trying to resolve imports to files that don't exist yet during the build
30+ // Plugin to mark React output imports as external ONLY during tsup's initial resolution
31+ // This prevents tsup from trying to resolve imports to files that don't exist yet
32+ // BUT we need to be careful: if these are marked external, they won't be bundled
33+ // The key is that this plugin only runs during esbuild's resolution, and we want
34+ // React outputs to be bundled together (not external) for minification
35+ //
36+ // Actually, the real issue is that files outside React dir import from ./react/out/...
37+ // When tsup builds, it shouldn't follow those imports. We need to prevent tsup
38+ // from following imports from files outside the entry points.
3239const externalReactOutputsPlugin = {
3340 name : 'external-react-outputs' ,
3441 setup ( build ) {
42+ // Only mark as external if the import is coming from outside the React source directory
43+ // This prevents tsup from trying to resolve imports from files like cortexideSettingsPane.ts
44+ // But allows React components to import each other normally (which should be bundled)
3545 build . onResolve ( { filter : / ^ \. \/ r e a c t \/ o u t \/ | ^ \. \. \/ r e a c t \/ o u t \/ / } , ( args ) => {
36- // Mark React output imports as external during build (they'll be available at runtime)
37- // This prevents DTS generation from failing when these files don't exist yet
38- return { path : args . path , external : true }
46+ // Check if the importer is outside the React source directory
47+ // If so, mark as external (these are runtime imports)
48+ // If not, let it be bundled (these are internal React component imports)
49+ if ( args . importer && ! args . importer . includes ( '/react/src' ) && ! args . importer . includes ( '/react/src2' ) ) {
50+ // This import is from outside React source, mark as external
51+ // This prevents tsup from trying to resolve it during build
52+ return { path : args . path , external : true }
53+ }
54+ // This is an internal import, let it be bundled
55+ return undefined
3956 } )
4057 }
4158}
@@ -64,18 +81,13 @@ export default defineConfig({
6481 outExtension : ( ) => ( { js : '.js' } ) ,
6582 treeshake : true ,
6683 // Mark Node.js built-ins and React output imports as external
67- // React outputs MUST be in the external array (not just plugin) because:
68- // 1. tsup does its own import resolution BEFORE esbuild
69- // 2. When tsup encounters imports from files outside React dir (e.g., cortexideSettingsPane.ts),
70- // it tries to resolve them during tsup's resolution phase
71- // 3. The external array is checked during tsup's phase, plugins only run during esbuild phase
72- // 4. If not in external array, tsup tries to resolve files that don't exist yet → fails
84+ // CRITICAL: React outputs MUST be in external array for tsup's resolution phase
85+ // BUT: The plugin will handle them during esbuild phase to allow bundling
86+ // The external array prevents tsup from trying to resolve imports from files outside React dir
7387 external : [
7488 'url' , 'module' , 'fs' , 'path' , 'os' , 'crypto' , 'stream' , 'util' , 'events' , 'buffer' , 'process' ,
7589 // React output imports - MUST be external at tsup level to prevent resolution errors
76- // tsup checks external array during its own resolution phase (before esbuild)
77- // If not listed here, tsup tries to resolve files that don't exist yet → fails
78- // These are the exact paths used in imports from files outside React directory
90+ // These prevent tsup from trying to resolve imports from files like cortexideSettingsPane.ts
7991 './react/out/void-editor-widgets-tsx/index.js' ,
8092 './react/out/void-settings-tsx/index.js' ,
8193 './react/out/sidebar-tsx/index.js' ,
0 commit comments