1import { getConfig } from '@expo/config'; 2import chalk from 'chalk'; 3 4import { Log } from '../../log'; 5import { WebSupportProjectPrerequisite } from '../../start/doctor/web/WebSupportProjectPrerequisite'; 6import { getPlatformBundlers } from '../../start/server/platformBundlers'; 7import { WebpackBundlerDevServer } from '../../start/server/webpack/WebpackBundlerDevServer'; 8import { CommandError } from '../../utils/errors'; 9import { setNodeEnv } from '../../utils/nodeEnv'; 10import { Options } from './resolveOptions'; 11 12export async function exportWebAsync(projectRoot: string, options: Options) { 13 // Ensure webpack is available 14 await new WebSupportProjectPrerequisite(projectRoot).assertAsync(); 15 16 setNodeEnv(options.dev ? 'development' : 'production'); 17 require('@expo/env').load(projectRoot); 18 19 const { exp } = getConfig(projectRoot); 20 const platformBundlers = getPlatformBundlers(exp); 21 // Create a bundler interface 22 const bundler = new WebpackBundlerDevServer(projectRoot, platformBundlers, false); 23 24 // If the user set `web.bundler: 'metro'` then they should use `expo export` instead. 25 if (!bundler.isTargetingWeb()) { 26 throw new CommandError( 27 chalk`{bold expo export:web} can only be used with Webpack. Use {bold expo export} for other bundlers.` 28 ); 29 } 30 31 Log.log(`Exporting with Webpack...`); 32 33 // Bundle the app 34 await bundler.bundleAsync({ 35 mode: options.dev ? 'development' : 'production', 36 clear: options.clear, 37 }); 38} 39