import path from 'path' ; import { build } from 'esbuild' ; export const definedGlobals = { global : 'window' , 'process.env.version' : JSON . stringify ( require ( '../studio/package.json' ) . version ) , } ; export function createBundles ( watch ) { for ( const which of [ 'core' , 'studio' ] ) { const pathToPackage = path . join ( __dirname , '../' , which ) ; const esbuildConfig = { entryPoints : [ path . join ( pathToPackage , 'src/index.ts' ) ] , target : [ 'es6' ] , loader : { '.png' : 'file' , '.svg' : 'dataurl' } , bundle : true , sourcemap : true , define : definedGlobals , watch , external : [ '@theatre/dataverse' , 'react' , 'react-dom' , 'styled-components' , ] , } ; if ( which === 'core' ) { esbuildConfig . platform = 'neutral' ; esbuildConfig . mainFields = [ 'browser' , 'module' , 'main' ] ; esbuildConfig . target = [ 'firefox57' , 'chrome58' ] ; esbuildConfig . conditions = [ 'browser' , 'node' ] ; } build ( { ... esbuildConfig , outfile : path . join ( pathToPackage , 'dist/index.js' ) , format : 'cjs' , } ) ; } }