Write back to Options within plugin? #8974
Replies: 1 comment
-
I needed to use an rsbuild plugin instead of an rspack plugin, as well as set the const PLUGIN_NAME = 'MiniflareServer';
import type {
RsbuildPlugin,
RsbuildPluginAPI,
} from '@rsbuild/core';
import { unstable_dev } from 'wrangler';
const PLUGIN_NAME = 'MiniflareServer';
class MiniflarePlugin implements RsbuildPlugin {
name = PLUGIN_NAME;
setup(api: RsbuildPluginAPI) {
api.modifyRsbuildConfig({
order: 'post',
handler: async (config, { mergeRsbuildConfig }) => {
if (config.mode !== 'development') return;
const miniflare = await unstable_dev('./functions/index.ts', {
experimental: { liveReload: true, testMode: false },
port: 8888,
});
return mergeRsbuildConfig(config, {
server: {
proxy: [
{
context: ['/api'],
router: () => `http://${miniflare?.address}:${miniflare?.port}`,
logLevel: 'error',
secure: false,
changeOrigin: true,
},
],
},
});
},
});
}
}
export const miniflarePlugin = () => new MiniflarePlugin(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to write back to the Options object within a plugin? My simple example spins up a secondary server, and then I want to apply DevServer proxy configuration once I know what the server address is.
However, this doesn't work. If I assign static values upfront via
rsbuild.config.ts
it works as expected. I know other frameworks like Vite allow you to do this (I'm porting from Vite where I wrote a similar plugin).I combed through the docs and didn't find anything that addressed this situation, and all plugin methods appear to return
void
, so passing the Options back out fromapply
doesn't seem the correct path.Beta Was this translation helpful? Give feedback.
All reactions