@@ -16,6 +16,10 @@ interface ProductionBlockProps {
1616 metadata ?: any ;
1717 context : FileContext | FolderContext
1818}
19+ interface BundleCode {
20+ name : string ;
21+ content : string ;
22+ }
1923export const ProductionBlock = ( props : ProductionBlockProps ) => {
2024 const {
2125 block,
@@ -25,15 +29,29 @@ export const ProductionBlock = (props: ProductionBlockProps) => {
2529 context,
2630 } = props ;
2731
28- const [ bundleCode , setBundleCode ] = useState ( "" ) ;
32+ const [ bundleCode , setBundleCode ] = useState < BundleCode [ ] > ( [ ] ) ;
2933 const [ iframeIsLoaded , setIframeIsLoaded ] = useState ( false ) ;
3034 const iframeElement = useRef < HTMLIFrameElement > ( null ) ;
3135
3236 const getContents = async ( ) => {
33- const content = await import (
34- `../../../dist/${ block . id } /index.js?raw`
35- ) . then ( ( m ) => m . default ) ;
36- setBundleCode ( content )
37+ const allContent = await import . meta. glob (
38+ `./../../dist/**`
39+ )
40+ const relevantPaths = Object . keys ( allContent ) . filter ( ( d : string ) => (
41+ d . startsWith ( `./../../dist/${ block . id } ` )
42+ ) )
43+ let relevantContent = [ ]
44+ for ( const path of relevantPaths ) {
45+ const importType = path . endsWith ( ".css" ) ? "inline" : "raw"
46+ const content = await import (
47+ `${ path } ?${ importType } `
48+ ) . then ( ( d ) => d . default )
49+ relevantContent . push ( {
50+ name : path . slice ( 13 ) ,
51+ content,
52+ } )
53+ }
54+ setBundleCode ( relevantContent )
3755 }
3856 useEffect ( ( ) => { getContents ( ) } , [ block . entry ] )
3957
0 commit comments