@gravity-ui/app-builder ·
Develop and build your client-server projects, powered by typescript and webpack.
Install
npm install --save-dev @gravity-ui/app-builder
@gravity-ui/app-builder is ESM-only and requires Node.js 20.19 or newer. Use import
or dynamic import() to load its API; CommonJS require() is not supported.
Usage
@gravity-ui/app-builder provides CLI (npx app-builder). You can view available commands with the --help flag.
Develop your project
npx app-builder dev # to view supported options add the --help flag.
Build your project
npx app-builder build # to view supported options add the --help flag.
Examples
Profile a Rspack build
npx app-builder dev --rspack-profile 'rspack_core=info'
See Rspack profiling for trace lifecycle, filters, environment
variables, and Perfetto analysis.
Configuration
You can use any of these files:
- app-builder.config.ts
- app-builder.config.mts
- app-builder.config.js
- app-builder.config.mjs
- app-builder.config.cjs
- app-builder.config.json
- app-builder property in your package.json
You can also specify a custom filename using the --config flag
TypeScript/JavaScript
import {defineConfig} from '@gravity-ui/app-builder';
export default defineConfig({
client: {
// client settings
},
server: {
// server settings
},
});
Conditional config
If the config needs to be conditionally determined, it can export a function instead:
import {defineConfig} from '@gravity-ui/app-builder';
export default defineConfig(
async function (
/** @type dev | build */
command,
/**
* values specified with --env flag
*
* @type {[k in string]: string}
*
* @example
* With follow command:
* app-build dev --env=path.to.member1=value1 --env=path.to.member2=value2
* you get:
* env = {path: {to: {member1: 'value1', member2: 'value2'}}}
*/
env,
) {
return {
verbose: command === 'dev',
client: {
// client settings
},
server: {
// server settings
},
};
},
);
export default config;
package.json
{
"app-builder": {
"client": {
// client settings
},
"server": {
// server settings
}
},
"scripts": {
"dev": "app-builder dev",
"build": "app-builder build"
}
}
Common
target (client | server) — select compilation unit.
verbose (boolean) - turn on verbose output.
Environment Variables
app-builder automatically injects environment variables during the build process that are available in your application code:
process.env.PUBLIC_PATH — automatically set to the resolved public path value (including CDN URLs if configured). This allows your application code to dynamically access the correct resource URLs at runtime.
// In your application code, you can access:
const publicPath = process.env.PUBLIC_PATH; // e.g., "https://cdn.example.com/build/" or "/build/"
// Useful for dynamically loading assets or configuring Module Federation
const assetUrl = `${process.env.PUBLIC_PATH}images/logo.png`;
Note: On the server side, process.env.PUBLIC_PATH is only available when using SWC compiler (compiler: 'swc'). With TypeScript compiler, this variable is not injected.
process.env.NODE_ENV — current environment ('development' | 'production')
process.env.IS_SSR — boolean flag indicating if code is running in SSR context
Server
app-builder compiles server with typescript.
Default folder for server code is src/server. There is must be file tsconfig.json
{
"compilerOptions": {
"outDir": "../../dist/server"
}
}
and index.ts - server entrypoint.
outDir - must be configured to place compiled files to {rootDir}/dist/server.
The server is started with the command node {rootDir}/dist/server/index.js.
Options
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/${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.
swcOptions.rootDir (string) — like rootDir in tsconfig: compiled files keep their path relative to it, so the output matches tsc. Needed when tsconfig paths point outside the app. Relative to the app root (note that tsconfig rootDir is relative to the tsconfig file); it must contain the app root and all compiled directories. outputPath defaults to the server directory's path relative to rootDir. The application restarts only on changes in outputPath; add the output of other compiled directories to watch.
swcOptions.copyFiles (boolean) — copy every file SWC does not compile (JSON, but also e.g. *.md or tsconfig.json) from the compiled directories to the output; use ignore to skip unwanted ones. package.json and node_modules are never copied. Unlike tsc, files imported from outside the compiled directories (e.g. ../../package.json) are not copied.
swcOptions.ignore (string[]) — globs of files to skip in compilation, copying and watching, relative to the app root. ** does not cross .., so match directories outside the app with patterns like ../other/tests/**. Applies to directories only: a tsconfig paths target that is a single file is always compiled.
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
app-builder bundles client with webpack. Client code must be in src/ui folder.
src/ui/entries - each file in this folder is used as entrypoint. dist/public/build is output directory for bundles.
Runtime public path (window.__PUBLIC_PATH__)
window.__PUBLIC_PATH__ is a global variable you set in your HTML page — it is not a config option. The build-time publicPath and publicPathPrefix options only affect the dev server and the value of process.env.PUBLIC_PATH; they do not control where the browser fetches async chunks at runtime. That base URL comes from window.__PUBLIC_PATH__.
app-builder prepends a tiny bootstrap module to every client entry that overrides webpack's __webpack_public_path__ from this global:
__webpack_public_path__ = window.__PUBLIC_PATH__;
Define it in the page before any bundle is loaded — e.g. in the <head> of index.html:
<script>
window.__PUBLIC_PATH__ = '/'; // path under which the build output is served
</script>
Set it to wherever the dist/public/build output is actually served: '/' if assets are served from the site root, '/build/' for the default layout, or a full origin such as 'https://cdn.example.com/build/' for a CDN.
If dynamic imports 404 at /build/js/... while other assets load from /js/..., or HMR breaks in dev, set this global — changing publicPath in config will not help.
If the runtime should retry another base URL when a chunk fails to load from this one, see publicPathFallback.
Options
All paths must be specified relative rootDir of the project.
modules (string[]) — Tell webpack what directories should be searched when resolving modules. modules automatically
populates with baseUrl from src/ui/tsconfig.json.
alias (Record<string, string>) — Create aliases to import or require certain modules more easily, more
With this {rootDir}/src/ui/tsconfig.json:
{
"compilerOptions": {
"baseDir": ".",
"paths": {
"~units": ["units/*"]
}
}
}
modules will contain ["{rootDir}/src"] and aliases - {"~units": ["{rootDir}/src/units"]};
includes (string[]) — additional compilation paths. Example: includes: ['node_modules/my-lib', 'src/shared']
images (string[]) — Additional paths for images. Example: images: ['node_modules/my-lib/img']
icons (string[]) — Additional paths for svg icons. By default, all svgs with paths including icons/ will be processed.
Example: icons: [node_modules/@fortawesome/fontawesome-pro/svgs]
publicPathPrefix (string) — publicPath prefix, will be added to /build/
publicPath (string) — publicPath for bundler, this option has higher priority than publicPathPrefix
outputPath (string) — Build directory for output, default: dist/public/build and dist/ssr - for SSR
assetsManifestFile (string) — File name for assets manifest, default: assets-manifest.json
symlinks (boolean) — Follow symbolic links while looking for a file. more
externals — specify dependencies that shouldn't be resolved by webpack, but should become dependencies of the resulting bundle. more
node — include polyfills or mocks for various node stuff. more
fallback — Redirect module requests when normal resolving fails. more
polyfill — allow enable Node.js process object polyfill.
hiddenSourceMap (boolean=true) - if false - source maps will be generated for prod builds
disableSourceMapGeneration (boolean) — disable sourcemap generation;
definitions — add additional options to DefinePlugin. more
svgr (SvgrConfig) — svgr plugin options. more
entry (string | string[] | Record<string, string | string[]>) — entry for bundler, overrides entry which is generated from entries directory
entryFilter (string[]) — filter used entrypoints.
excludeFromClean (string[]) — do not clean provided paths before build.
forkTsCheker (false | ForkTsCheckerWebpackPluginOptions) - config for ForkTsCheckerWebpackPlugin more. If false, ForkTsCheckerWebpackPlugin will be disabled.
cache (boolean | FileCacheOptions | MemoryCacheOptions) — Cache the generated webpack modules and chunks to improve build speed. more
bundler ('webpack' | 'rspack') - Option to choose a bundler.
javaScriptLoader ('babel' | 'swc') - Option to choose a JavaScript loader.
babel ((config: babel.TransformOptions, options: {configType: 'development' | 'production'; isSsr: boolean}) => babel.TransformOptions | Promise<babel.TransformOptions>) - Allow override the default babel transform options.
babelCacheDirectory (boolean | string) — Set directory for babel-loader cache (`default: node_modules/.cache/babel-loader``)