Skip to content
Closed
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
14 changes: 14 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,20 @@ createServer()
}
```

### server.publicPath

- **Type:** `string`

This option allows the user to customize the URL prefix. Example:

```js
export default {
server: {
publicPath: 'http://127.0.0.1:8080/'
}
}
Comment on lines +534 to +538
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to use defineConfig everywhere in the docs, so folks know that this is a thing and prefer to use it

Suggested change
export default {
server: {
publicPath: 'http://127.0.0.1:8080/'
}
}
export default defineConfig({
server: {
publicPath: 'http://127.0.0.1:8080/'
}
})

```

## Build Options

### build.target
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ function fileToDevUrl(id: string, config: ResolvedConfig) {
// (this is special handled by the serve static middleware
rtn = path.posix.join(FS_PREFIX + id)
}
return config.base + rtn.replace(/^\//, '')
const publicPath = config.server?.publicPath || ''
return publicPath + config.base + rtn.replace(/^\//, '')
}

export function getAssetFilename(
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface ServerOptions {
* Options for files served via '/\@fs/'.
*/
fs?: FileSystemServeOptions
publicPath?: string
}

export interface ResolvedServerOptions extends ServerOptions {
Expand Down