Skip to content

Commit

Permalink
fix: Fix config hook implementations for vite plugins
Browse files Browse the repository at this point in the history
Turns out the returned config is merged with the user config, so we don't have to do that ourselves.
  • Loading branch information
aklinker1 committed Jul 13, 2023
1 parent fa2b656 commit 49965e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
21 changes: 9 additions & 12 deletions src/core/vite-plugins/devHtmlPrerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ export function devHtmlPrerender(config: InternalConfig): vite.Plugin {
return {
apply: 'build',
name: 'wxt:dev-html-prerender',
config(userConfig) {
return vite.mergeConfig(
{
resolve: {
alias: {
'@wxt/reload-html': resolve(
config.root,
'node_modules/wxt/dist/virtual-modules/reload-html.js',
),
},
config() {
return {
resolve: {
alias: {
'@wxt/reload-html': resolve(
config.root,
'node_modules/wxt/dist/virtual-modules/reload-html.js',
),
},
},
userConfig,
);
};
},
async transform(html, id) {
const server = config.server;
Expand Down
19 changes: 10 additions & 9 deletions src/core/vite-plugins/devServerGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import { InternalConfig } from '../types';
export function devServerGlobals(internalConfig: InternalConfig): Plugin {
return {
name: 'wxt:dev-server-globals',
config(config) {
config() {
if (internalConfig.server == null || internalConfig.command == 'build')
return;

config.define ??= {};
config.define.__DEV_SERVER_PROTOCOL__ = JSON.stringify('ws:');
config.define.__DEV_SERVER_HOSTNAME__ = JSON.stringify(
internalConfig.server.hostname,
);
config.define.__DEV_SERVER_PORT__ = JSON.stringify(
internalConfig.server.port,
);
return {
define: {
__DEV_SERVER_PROTOCOL__: JSON.stringify('ws:'),
__DEV_SERVER_HOSTNAME__: JSON.stringify(
internalConfig.server.hostname,
),
__DEV_SERVER_PORT__: JSON.stringify(internalConfig.server.port),
},
};
},
};
}

0 comments on commit 49965e7

Please sign in to comment.