diff --git a/packages/core/src/server/middlewares/htmlFallback.ts b/packages/core/src/server/middlewares/htmlFallback.ts index 4d1265511..51c829fb0 100644 --- a/packages/core/src/server/middlewares/htmlFallback.ts +++ b/packages/core/src/server/middlewares/htmlFallback.ts @@ -25,7 +25,7 @@ export function htmlFallbackMiddleware( } const url = cleanUrl(req.url); const pathname = removeSlash(decodeURIComponent(url)); - const headers = app.resolvedUserConfig.server.headers; + const headers = app.config.server.headers; if (pathname.endsWith('.html')) { const html = app.compiler.resource(pathname); diff --git a/packages/core/src/server/middlewares/lazyCompilation.ts b/packages/core/src/server/middlewares/lazyCompilation.ts index dbd66bf50..bad1b9749 100644 --- a/packages/core/src/server/middlewares/lazyCompilation.ts +++ b/packages/core/src/server/middlewares/lazyCompilation.ts @@ -20,7 +20,7 @@ export function lazyCompilationMiddleware( app: Server ): Connect.NextHandleFunction { return async function handleLazyCompilationMiddleware(req, res, next) { - const { resolvedUserConfig, compiler } = app; + const { config, compiler } = app; if (!req.url.startsWith(DEFAULT_LAZY_COMPILATION_PATH)) { return await next(); @@ -44,7 +44,7 @@ export function lazyCompilationMiddleware( }) .join(', '); - resolvedUserConfig.logger.info( + config.logger.info( `${bold(green('✨Lazy compiling'))} ${bold(cyan(pathsStr))}`, true ); @@ -62,19 +62,15 @@ export function lazyCompilationMiddleware( return next(); } - if (isNodeEnvironment || resolvedUserConfig.server.writeToDisk) { + if (isNodeEnvironment || config.server.writeToDisk) { compiler.writeResourcesToDisk(); } - resolvedUserConfig.logger.info( + config.logger.info( `${bold(green(`✓ Lazy compilation done`))} ${bold( cyan(pathsStr) )} in ${bold( - green( - resolvedUserConfig.logger.formatExecutionTime( - performance.now() - start - ) - ) + green(config.logger.formatExecutionTime(performance.now() - start)) )}.` ); diff --git a/packages/core/src/server/middlewares/proxy.ts b/packages/core/src/server/middlewares/proxy.ts index f4699b3b7..dee3c6f0a 100644 --- a/packages/core/src/server/middlewares/proxy.ts +++ b/packages/core/src/server/middlewares/proxy.ts @@ -27,7 +27,7 @@ export function proxyMiddleware( middlewareServer: HttpServer, config: NonNullable ): Connect.NextHandleFunction { - const { resolvedUserConfig } = app; + const { config: resolvedUserConfig } = app; const proxies: Record = {}; Object.keys(config).forEach((context) => { diff --git a/packages/core/src/server/middlewares/resource.ts b/packages/core/src/server/middlewares/resource.ts index d3e08f7a3..8ab26a75f 100644 --- a/packages/core/src/server/middlewares/resource.ts +++ b/packages/core/src/server/middlewares/resource.ts @@ -26,7 +26,7 @@ export function resourceMiddleware(app: Server): Connect.NextHandleFunction { return next(); } const url = cleanUrl(req.url); - const { compiler, resolvedUserConfig: config, publicPath } = app; + const { compiler, config, publicPath } = app; if (compiler._isInitialCompile) { await compiler.waitForInitialCompileFinish(); diff --git a/packages/core/src/server/middlewares/static.ts b/packages/core/src/server/middlewares/static.ts index 342edd6ed..483d815bc 100644 --- a/packages/core/src/server/middlewares/static.ts +++ b/packages/core/src/server/middlewares/static.ts @@ -23,12 +23,12 @@ import sirv, { Options } from 'sirv'; import type { Server } from '../index.js'; export function staticMiddleware(app: Server): Connect.NextHandleFunction { - const { resolvedUserConfig, compiler } = app; + const { config, compiler } = app; const root = compiler.config.root; const serve = sirv( root, sirvOptions({ - getHeaders: () => resolvedUserConfig.server.headers + getHeaders: () => config.server.headers }) ); return function handleStaticMiddleware(req, res, next) { @@ -61,7 +61,7 @@ export function staticMiddleware(app: Server): Connect.NextHandleFunction { } export function publicMiddleware(app: Server): Connect.NextHandleFunction { - const { resolvedUserConfig: config, publicDir, publicFiles } = app; + const { config: config, publicDir, publicFiles } = app; const serve = sirv( publicDir, sirvOptions({ diff --git a/packages/core/src/server/preview.ts b/packages/core/src/server/preview.ts index 600e273ae..13c000ddb 100644 --- a/packages/core/src/server/preview.ts +++ b/packages/core/src/server/preview.ts @@ -50,7 +50,7 @@ export interface PreviewServerOptions extends CommonServerOptions { * @class */ export class PreviewServer extends httpServer { - resolvedUserConfig: ResolvedUserConfig; + config: ResolvedUserConfig; previewServerOptions: PreviewServerOptions; httpsOptions: SecureServerOptions; @@ -77,7 +77,7 @@ export class PreviewServer extends httpServer { * @throws {Error} If the server cannot be started. */ async createPreviewServer(): Promise { - this.resolvedUserConfig = await resolveConfig( + this.config = await resolveConfig( this.inlineConfig, 'preview', 'production', @@ -85,7 +85,7 @@ export class PreviewServer extends httpServer { true ); - this.logger = this.resolvedUserConfig.logger; + this.logger = this.config.logger; await this.#resolveOptions(); @@ -115,7 +115,7 @@ export class PreviewServer extends httpServer { */ #initializeMiddlewares() { const { cors, proxy } = this.previewServerOptions; - const { appType, middlewareMode } = this.resolvedUserConfig.server; + const { appType, middlewareMode } = this.config.server; if (cors !== false) { this.app.use(corsMiddleware(typeof cors === 'boolean' ? {} : cors)); @@ -154,7 +154,7 @@ export class PreviewServer extends httpServer { const { server, compilation: { root, output } - } = this.resolvedUserConfig; + } = this.config; this.publicPath = output.publicPath ?? '/'; const preview = server?.preview; @@ -174,7 +174,7 @@ export class PreviewServer extends httpServer { this.serve = sirv(distDir, { etag: true, dev: true, - single: this.resolvedUserConfig.server.appType === 'spa', + single: this.config.server.appType === 'spa', ignores: false, setHeaders: (res, pathname) => { if (knownJavascriptExtensionRE.test(pathname)) { @@ -224,13 +224,13 @@ export class PreviewServer extends httpServer { this.resolvedUrls = await resolveServerUrls( this.httpServer, - this.resolvedUserConfig, + this.config, 'preview' ); const shortFile = getShortName( - this.resolvedUserConfig.configFilePath, - this.resolvedUserConfig.root + this.config.configFilePath, + this.config.root ); this.logger.info(`Using config file at ${bold(green(shortFile))}`);