Files
wxt/src/core/vite-plugins/devServerGlobals.ts
T
Aaron Klinker 49965e7786 fix: Fix config hook implementations for vite plugins
Turns out the returned config is merged with the user config, so we don't have to do that ourselves.
2023-07-13 16:36:39 -05:00

26 lines
723 B
TypeScript

import { Plugin } from 'vite';
import { InternalConfig } from '../types';
/**
* Defines global constants about the dev server. Helps scripts connect to the server's web socket.
*/
export function devServerGlobals(internalConfig: InternalConfig): Plugin {
return {
name: 'wxt:dev-server-globals',
config() {
if (internalConfig.server == null || internalConfig.command == 'build')
return;
return {
define: {
__DEV_SERVER_PROTOCOL__: JSON.stringify('ws:'),
__DEV_SERVER_HOSTNAME__: JSON.stringify(
internalConfig.server.hostname,
),
__DEV_SERVER_PORT__: JSON.stringify(internalConfig.server.port),
},
};
},
};
}