project.json:

1"myapp": { 2 "targets": { 3 "serve": { 4 "executor": "@nx/web:file-server", 5 "options": { 6 "buildTarget": "build", 7 "port": 3000, 8 }, 9 }, 10 "build": { 11 "outputs": ["{workspaceRoot}/dist/myapp"], 12 "command": "echo 'Generating index.html' && mkdir -p dist && echo '<h1>Works</h1>' > dist/myapp/index.html" 13 }, 14 } 15} 16

โฏ

nx serve myapp

Examples

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

โฏ

nx serve myapp -d

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

Options

spa

boolean
Default: false

Redirect 404 errors to index.html (useful for SPA's)

buildTarget

string

Target which builds the application.

brotli

boolean
Default: false

Enable brotli compression

cors

oneOf [boolean, string]
Default: true

Enable CORS

cacheSeconds

number
Default: -1

Set cache time (in seconds) for cache-control max-age header. To disable caching, use -1. Caching defaults to disabled.

gzip

boolean
Default: false

Enable gzip compression

host

string
Default: localhost

Host to listen on.

maxParallel

number

Max number of parallel jobs.

parallel

boolean
Default: true

Build the target in parallel.

port

number
Default: 4200

Port to listen on.

proxyUrl

string

URL 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.

proxyOptions

Default: {}

Options for the proxy used by http-server.

ssl

boolean
Default: false

Serve using HTTPS.

sslKey

string

SSL key to use for serving HTTPS.

sslCert

string

SSL certificate to use for serving HTTPS.

staticFilePath

string

Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath

watch

boolean
Default: true

Watch for file changes.

Additional Properties

anything

Extra properties of any type may be provided to this object.