Skip to content

Commit

Permalink
fix: Allow custom asset URL origin in development (#5104)
Browse files Browse the repository at this point in the history
Co-authored-by: 2359634711 <2359634711@qq.com>
  • Loading branch information
innocenzi and jianqi-jin committed Sep 27, 2021
1 parent fb37a63 commit e4ef6dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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

0 comments on commit e4ef6dd

Please sign in to comment.