Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow custom asset URL origin in development #5104

Merged
merged 1 commit into from Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/config/index.md
Expand Up @@ -575,6 +575,19 @@ createServer()
})
```

### server.origin

- **Type:** `string`

Defines the origin of the generated asset URLs during development.

```js
export default defineConfig({
server: {
origin: '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
Expand Up @@ -176,7 +176,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 origin = config.server?.origin ?? ''
return origin + config.base + rtn.replace(/^\//, '')
}

export function getAssetFilename(
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -130,6 +130,10 @@ export interface ServerOptions {
* Options for files served via '/\@fs/'.
*/
fs?: FileSystemServeOptions
/**
* Origin for the generated asset URLs.
*/
origin?: string
}

export interface ResolvedServerOptions extends ServerOptions {
Expand Down