From c8a5629359a5b2f2afcee37e4e813cff2bbcda97 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Mon, 4 Mar 2024 13:54:14 +0100 Subject: [PATCH] fix: createRuntime --- src/vite.ts | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/vite.ts b/src/vite.ts index 5cabf17..a514a5b 100644 --- a/src/vite.ts +++ b/src/vite.ts @@ -9,12 +9,7 @@ import { readFileSync } from 'node:fs' import type { ViteRuntime } from 'vite/runtime' -import { - createViteRuntime, - MainThreadRuntimeOptions, - type Manifest, - type ViteDevServer, -} from 'vite' +import type { MainThreadRuntimeOptions, Manifest, ViteDevServer } from 'vite' import { makeAttributes, uniqBy } from './utils.js' import type { AdonisViteElement, SetAttributes, ViteOptions } from './types.js' @@ -30,7 +25,6 @@ export class Vite { */ #manifestCache?: Manifest #options: ViteOptions - #runtime?: ViteRuntime #devServer?: ViteDevServer constructor( @@ -325,14 +319,23 @@ export class Vite { * since we don't need it */ async createDevServer() { - const { createViteRuntime, createServer } = await import('vite') + const { createServer } = await import('vite') this.#devServer = await createServer({ server: { middlewareMode: true, hmr: { port: 3001 } }, appType: 'custom', }) + } + + /** + * Create a runtime instance + * Will not be available when running in production since + * it needs the Vite Dev server + */ + async createRuntime(options: MainThreadRuntimeOptions = {}): Promise { + const { createViteRuntime } = await import('vite') - this.#runtime = await createViteRuntime(this.#devServer) + return createViteRuntime(this.#devServer!, options) } /** @@ -350,15 +353,6 @@ export class Vite { return this.#devServer } - /** - * Create a runtime instance - * Will not be available when running in production since - * it needs the Vite Dev server - */ - createRuntime(options: MainThreadRuntimeOptions = {}) { - return createViteRuntime(this.#devServer!, options) - } - /** * Returns the script needed for the HMR working with React */