This PR adds the ability to set the port of the React application when using the generator. e.g. ```shell npx nx g @nx/react:app --port 8080 ``` This is useful when generating multiple apps and then running them in parallel.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { type Tree, readNxJson } from '@nx/devkit';
|
|
import { getE2EWebServerInfo } from '@nx/devkit/src/generators/e2e-web-server-info-utils';
|
|
|
|
export async function getWebpackE2EWebServerInfo(
|
|
tree: Tree,
|
|
projectName: string,
|
|
configFilePath: string,
|
|
isPluginBeingAdded: boolean,
|
|
e2ePortOverride?: number
|
|
) {
|
|
const nxJson = readNxJson(tree);
|
|
let e2ePort = e2ePortOverride ?? 4200;
|
|
|
|
if (
|
|
nxJson.targetDefaults?.['serve'] &&
|
|
nxJson.targetDefaults?.['serve'].options?.port
|
|
) {
|
|
e2ePort = nxJson.targetDefaults?.['serve'].options?.port;
|
|
}
|
|
|
|
return getE2EWebServerInfo(
|
|
tree,
|
|
projectName,
|
|
{
|
|
plugin: '@nx/webpack/plugin',
|
|
serveTargetName: 'serveTargetName',
|
|
serveStaticTargetName: 'serveStaticTargetName',
|
|
configFilePath,
|
|
},
|
|
{
|
|
defaultServeTargetName: 'serve',
|
|
defaultServeStaticTargetName: 'serve-static',
|
|
defaultE2EWebServerAddress: `http://localhost:${e2ePort}`,
|
|
defaultE2ECiBaseUrl: `http://localhost:${e2ePort}`,
|
|
defaultE2EPort: e2ePort,
|
|
},
|
|
isPluginBeingAdded
|
|
);
|
|
}
|