Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ All server settings are used only in dev mode:

- `port` (`number | true`) — specify port that server listens. The port will be used to
pass through requests from the client to the server. If set to `true`, the port will be selected automatically.
The server is started with the command `APP_PORT=${port} node dist/server/index.js --port ${port}`.
The server is started with the command `APP_PORT=${port} node dist/${outputPath}/index.js --port ${port}`.
- `watch` (`string[]`) — by default `app-builder` monitors only `src/server` directory.
If you need to watch other directories, specify them here.
- `watchThrottle` (`number`) — use to add an extra throttle, or delay restarting.
- `inspect/inspectBrk` (`number | true`) — listen for a debugging client on specified port.
If specified `true`, try to listen on `9229`.
- `compiler` (`'typescript' | 'swc'`) — choose TypeScript compiler for server code compilation.
Default is `'typescript'`. Set to `'swc'` for faster compilation with SWC.
- `outputPath` (`string`) — custom output path for compiled server code relative to `dist` directory.
Default: `server`. Use this when your `server` entrypoint changed from `dist/server` to a different location (e.g., `package/src/server` for path `dist/package/src/server` in monorepo setups).

### Client

Expand Down
4 changes: 1 addition & 3 deletions src/commands/dev/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as path from 'node:path';
import * as fs from 'node:fs';
import nodemon from 'nodemon';
import {onExit} from 'signal-exit';
import {rimraf} from 'rimraf';

import {createRunFolder, getAppRunPath, shouldCompileTarget} from '../../common/utils';
import logger from '../../common/logger';
import paths from '../../common/paths';

import type WebpackDevServer from 'webpack-dev-server';
import type {NormalizedServiceConfig} from '../../common/models';
Expand Down Expand Up @@ -38,7 +36,7 @@ export default async function (config: NormalizedServiceConfig) {
let serverCompiled = !shouldCompileServer;
let needToStartNodemon = shouldCompileServer;

const serverPath = path.resolve(paths.appDist, 'server');
const serverPath = config.server.outputPath;
const {inspect, inspectBrk} = config.server;

const startNodemon = () => {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/dev/server.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from 'node:path';
import {rimraf} from 'rimraf';

import {ControllableScript} from '../../common/child-process/controllable-script';
Expand Down Expand Up @@ -58,7 +57,7 @@ watch(
export async function watchServerCompilation(
config: NormalizedServiceConfig,
): Promise<ControllableScript> {
const serverPath = path.resolve(paths.appDist, 'server');
const serverPath = config.server.outputPath;
rimraf.sync(serverPath);

const build = new ControllableScript(
Expand Down
5 changes: 5 additions & 0 deletions src/common/config.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {stripIndent} from 'common-tags';

import {isLibraryConfig, isServiceConfig} from './models';
import paths from './paths';

import type {Loader} from 'cosmiconfig';
import type {CosmiconfigResult} from 'cosmiconfig/dist/types';
Expand All @@ -23,16 +24,16 @@
import {getPort, hasMFAssetsIsolation} from './utils';
import logger from './logger';

function splitPaths(paths: string | string[]) {

Check warning on line 27 in src/common/config.ts

View workflow job for this annotation

GitHub Actions / Verify Files

'paths' is already declared in the upper scope on line 8 column 8
return (Array.isArray(paths) ? paths : [paths]).flatMap((p) => p.split(','));
}

function remapPaths(paths: string | string[]) {

Check warning on line 31 in src/common/config.ts

View workflow job for this annotation

GitHub Actions / Verify Files

'paths' is already declared in the upper scope on line 8 column 8
return splitPaths(paths).map((p) => path.resolve(process.cwd(), p));
}

function omitUndefined<T extends object>(obj: T) {
const newObj: Record<string, any> = {};

Check warning on line 36 in src/common/config.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
for (const [key, value] of Object.entries(obj)) {
if (value !== undefined) {
newObj[key] = value;
Expand Down Expand Up @@ -177,6 +178,10 @@
inspect: undefined,
inspectBrk: undefined,
compiler: serverConfig.compiler || 'typescript',
outputPath: path.resolve(
paths.appDist,
serverConfig.outputPath ? serverConfig.outputPath : 'server',
),
};
if (mode === 'dev') {
if (serverConfig.port === true) {
Expand Down
11 changes: 10 additions & 1 deletion src/common/models/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ export interface ServerConfig {
additionalPaths?: string[];
exclude?: string | string[];
};

/**
* Custom output path for compiled server code.
* Can be only relative to dist path.
* @default 'server'
* @example 'package/src/server'
*/
outputPath?: string;
}
export interface ServiceConfig {
target?: 'client' | 'server';
Expand Down Expand Up @@ -476,13 +484,14 @@ export type NormalizedClientConfig = Omit<

export type NormalizedServerConfig = Omit<
ServerConfig,
'port' | 'inspect' | 'inspectBrk' | 'compiler'
'port' | 'inspect' | 'inspectBrk' | 'compiler' | 'outputPath'
> & {
port?: number;
verbose?: boolean;
inspect?: number;
inspectBrk?: number;
compiler: ServerCompiler;
outputPath: string;
};

export type NormalizedServiceConfig = Omit<ServiceConfig, 'client' | 'server'> & {
Expand Down
Loading