Skip to content

Commit

Permalink
fix: Allow custom asset URL origin in development (vitejs#5104)
Browse files Browse the repository at this point in the history
Co-authored-by: 2359634711 <2359634711@qq.com>
  • Loading branch information
2 people authored and aleclarson committed Nov 8, 2021
1 parent 553d99b commit 6817158
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 6817158

Please sign in to comment.