Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HACKDAYS] O2 cache #2283

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Refactor oxygen plugin
  • Loading branch information
frandiox committed Jul 17, 2024
commit 8e94a0cf921b24bcf8fb8726824554ddd98716f0
22 changes: 12 additions & 10 deletions packages/mini-oxygen/src/vite/plugin.ts
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ export function oxygen(pluginOptions: OxygenPluginOptions = {}): Plugin[] {
let resolvedConfig: ResolvedConfig;
let absoluteWorkerEntryFile: string;
let apiOptions: OxygenApiOptions = {};
let entry = pluginOptions?.entry ?? DEFAULT_SSR_ENTRY;

return [
{
@@ -61,7 +62,7 @@ export function oxygen(pluginOptions: OxygenPluginOptions = {}): Plugin[] {
config.build?.ssr === true
? // No --entry flag passed by the user, use the
// option passed to the plugin or the default value
pluginOptions.entry ?? DEFAULT_SSR_ENTRY
entry
: // --entry flag passed by the user, keep it
config.build?.ssr,
},
@@ -81,18 +82,19 @@ export function oxygen(pluginOptions: OxygenPluginOptions = {}): Plugin[] {
};
},
},
configureServer: {
order: 'pre',
handler: (viteDevServer) => {
const entry =
apiOptions.entry ?? pluginOptions.entry ?? DEFAULT_SSR_ENTRY;

// For transform hook:
resolvedConfig = viteDevServer.config;
configResolved: {
order: 'post',
handler(config) {
entry = apiOptions.entry ?? pluginOptions?.entry ?? DEFAULT_SSR_ENTRY;
resolvedConfig = config;
absoluteWorkerEntryFile = path.isAbsolute(entry)
? entry
: path.resolve(resolvedConfig.root, entry);

},
},
configureServer: {
order: 'pre',
handler(viteDevServer) {
return () => {
setupOxygenMiddleware(viteDevServer, async () => {
const remoteEnv = await Promise.resolve(apiOptions.envPromise);