nx/packages/web/docs/file-server-examples.md
Jack Hsu fcb6498e76
feat(web): allow additional http-server options to be passed from @nx/web:file-server (#26391)
This PR allows additional args such as `-d` (directory listing) and
`--mimetypes` to be passed from `serve` to the underlying `http-server`
module.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #22138
2024-06-05 13:08:42 -04:00

45 lines
946 B
Markdown

---
title: Examples for the Web file-server executor
description: This page contains examples for the Vite @nx/web:file-server executor.
---
`project.json`:
```json5
"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"
},
}
}
```
```shell
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:
```shell
nx serve myapp -d
```
Refer to the [`http-server`](https://www.npmjs.com/package/http-server) package for all available options.
{% /tab %}
{% /tabs %}