Skip to content

The @nx/web plugin provides various executors to help you create and configure web projects within your Nx workspace. Below is a complete reference for all available executors and their options.

file-server

Serve a web application from a folder. This executor is a wrapper around the http-server package.

project.json:

"myapp": {
"targets": {
"serve": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
"port": 3000,
},
},
"build": {
"outputs": ["{workspaceRoot}/dist/myapp"],
"command": "echo 'Generating index.html' && mkdir -p dist && echo '<h1>Works</h1>' > dist/myapp/index.html"
},
}
}
Terminal window
nx serve myapp

Examples

{% tabs %} {% tab label=“Additional http-server options” %}

There are additional options from http-server that can be passed as CLI args. For example, to enable directory listing, pass -d as follows:

Terminal window
nx serve myapp -d

Refer to the http-server package for all available options.

{% /tab %} {% /tabs %}

Options

OptionTypeDescriptionDefault
brotlibooleanEnable brotli compressionfalse
buildTargetstringTarget which builds the application.
cacheSecondsnumberSet cache time (in seconds) for cache-control max-age header. To disable caching, use -1. Caching defaults to disabled.-1
corsstringEnable CORStrue
gzipbooleanEnable gzip compressionfalse
hoststringHost to listen on."localhost"
maxParallelnumberMax number of parallel jobs.
parallelbooleanBuild the target in parallel.true
portnumberPort to listen on.4200
proxyOptionsobjectOptions for the proxy used by http-server.{}
proxyUrlstringURL to proxy unhandled requests to. Note: If the ‘spa’ flag is set to true, manually setting this value will override the catch-all redirect functionality from http-server which may lead to unexpected behavior.
spabooleanRedirect 404 errors to index.html (useful for SPA’s)false
sslbooleanServe using HTTPS.false
sslCertstringSSL certificate to use for serving HTTPS.
sslKeystringSSL key to use for serving HTTPS.
staticFilePathstringPath where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath
watchbooleanWatch for file changes.true