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 { Options } from './resolveOptions';
10
11export async function exportWebAsync(projectRoot: string, options: Options) {
12  // Ensure webpack is available
13  await new WebSupportProjectPrerequisite(projectRoot).assertAsync();
14
15  const { exp } = getConfig(projectRoot);
16  const platformBundlers = getPlatformBundlers(exp);
17  // Create a bundler interface
18  const bundler = new WebpackBundlerDevServer(projectRoot, platformBundlers, false);
19
20  // If the user set `web.bundler: 'metro'` then they should use `expo export` instead.
21  if (!bundler.isTargetingWeb()) {
22    throw new CommandError(
23      chalk`{bold expo export:web} can only be used with Webpack. Use {bold expo export} for other bundlers.`
24    );
25  }
26
27  Log.log(`Exporting with Webpack...`);
28
29  // Bundle the app
30  await bundler.bundleAsync({
31    mode: options.dev ? 'development' : 'production',
32    clear: options.clear,
33  });
34}
35