API › @qwik.dev/qwik/optimizer

basename

basename(path: string, ext?: string): string;

Parameter

Type

Description

path

string

ext

string

(Optional)

Returns:

string

blockSSR

BundleGraphAdder

A function that returns a map of bundle names to their dependencies.

export type BundleGraphAdder = (manifest: QwikManifest) => Record<
  string,
  {
    imports?: string[];
    dynamicImports?: string[];
  }
>;

References: QwikManifest

Edit this section

ComponentEntryStrategy

export interface ComponentEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'component'

createOptimizer

createOptimizer: (optimizerOptions?: OptimizerOptions) => Promise<Optimizer>;

Parameter

Type

Description

optimizerOptions

OptimizerOptions

(Optional)

Returns:

Promise<Optimizer>

Diagnostic

export interface Diagnostic

Property

Modifiers

Type

Description

category

DiagnosticCategory

code

string | null

file

string

highlights

SourceLocation[] | null

message

string

scope

string

suggestions

string[] | null

DiagnosticCategory

export type DiagnosticCategory = "error" | "warning" | "sourceError";

dirname

dirname(path: string): string;

Parameter

Type

Description

path

string

Returns:

string

each

EmitMode

export type EmitMode = "dev" | "prod" | "lib" | "hmr";

EntryStrategy

export type EntryStrategy =
  | InlineEntryStrategy
  | HoistEntryStrategy
  | SingleEntryStrategy
  | HookEntryStrategy
  | SegmentEntryStrategy
  | ComponentEntryStrategy
  | SmartEntryStrategy;

References: InlineEntryStrategy, HoistEntryStrategy, SingleEntryStrategy, HookEntryStrategy, SegmentEntryStrategy, ComponentEntryStrategy, SmartEntryStrategy

errorBoundary

ExperimentalFeatures

Use false to check if feature x is enabled. It will be replaced with true or false via an exact string replacement.

Add experimental features to this enum definition.

export declare enum ExperimentalFeatures

Member

Value

Description

blockSSR

"blockSSR"

Enable the blockSSR: false route loader option

each

"each"

Enable the Each keyed-list primitive

errorBoundary

"errorBoundary"

Enable the ErrorBoundary primitive

insights

"insights"

Enable the ability to use the Qwik Insights vite plugin and <Insights/> component

noSPA

"noSPA"

Disable SPA navigation handler in Qwik Router

show

"show"

Enable the Show conditional primitive

suspense

"suspense"

Enable the Suspense fallback primitive

valibot

"valibot"

Enable the Valibot form validation

Edit this section

extname

extname(path: string): string;

Parameter

Type

Description

path

string

Returns:

string

format

format(pathObject: {
        root: string;
        dir: string;
        base: string;
        ext: string;
        name: string;
    }): string;

Parameter

Type

Description

pathObject

{ root: string; dir: string; base: string; ext: string; name: string; }

Returns:

string

GlobalInjections

export interface GlobalInjections

Property

Modifiers

Type

Description

attributes?

{ [key: string]: string; }

(Optional)

location

'head' | 'body'

tag

string

Edit this section

HoistEntryStrategy

export interface HoistEntryStrategy

Property

Modifiers

Type

Description

type

'hoist'

HookEntryStrategy

Warning: This API is now obsolete.

Use SegmentStrategy instead

export interface HookEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'hook'

InlineEntryStrategy

export interface InlineEntryStrategy

Property

Modifiers

Type

Description

type

'inline'

insights

isAbsolute

isAbsolute(path: string): boolean;

Parameter

Type

Description

path

string

Returns:

boolean

join

join(...paths: string[]): string;

Parameter

Type

Description

paths

string[]

Returns:

string

MinifyMode

export type MinifyMode = "simplify" | "none";

normalize

normalize(path: string): string;

Parameter

Type

Description

path

string

Returns:

string

noSPA

Optimizer

export interface Optimizer

Property

Modifiers

Type

Description

sys

OptimizerSystem

Optimizer system use. This can be updated with a custom file system.

Method

Description

transformModules(opts)

Transforms the input code string, does not access the file system.

OptimizerOptions

export interface OptimizerOptions

Property

Modifiers

Type

Description

_optimizer?

unknown

(Optional)

binding?

any

(Optional)

inlineStylesUpToBytes?

number

(Optional) Inline the global styles if they're smaller than this

sourcemap?

boolean

(Optional) Enable sourcemaps

sys?

OptimizerSystem

(Optional)

tsOptimizer?

boolean

(Optional) Use the TypeScript optimizer (@qwik.dev/ts-optimizer) instead of the Rust one.

Default false

OptimizerSystem

export interface OptimizerSystem

Property

Modifiers

Type

Description

cwd

() => string

dynamicImport

(path: string) => Promise<any>

env

SystemEnvironment

getInputFiles?

(rootDir: string) => Promise<TransformModuleInput[]>

(Optional)

os

string

path

Path

strictDynamicImport

(path: string) => Promise<any>

parse

parse(path: string): {
        root: string;
        dir: string;
        base: string;
        ext: string;
        name: string;
    };

Parameter

Type

Description

path

string

Returns:

{ root: string; dir: string; base: string; ext: string; name: string; }

Path

export interface Path

Property

Modifiers

Type

Description

delimiter

readonly

string

posix

readonly

Path

sep

readonly

string

win32

readonly

null

Method

Description

basename(path, ext)

dirname(path)

extname(path)

format(pathObject)

isAbsolute(path)

join(paths)

normalize(path)

parse(path)

relative(from, to)

resolve(paths)

QwikAsset

export interface QwikAsset

Property

Modifiers

Type

Description

name

string | undefined

Name of the asset

size

number

Size of the asset

Edit this section

QwikBuildMode

export type QwikBuildMode = "production" | "development";

Edit this section

QwikBuildTarget

export type QwikBuildTarget = "client" | "ssr" | "lib" | "test";

Edit this section

QwikBundle

export interface QwikBundle

Property

Modifiers

Type

Description

dynamicImports?

string[]

(Optional) Dynamic imports

imports?

string[]

(Optional) Direct imports

interactivity?

number

(Optional) Interactivity score of the bundle

origins?

string[]

(Optional) Source files of the bundle

size

number

Size of the bundle

symbols?

string[]

(Optional) Symbols in the bundle

total

number

Total size of this bundle's static import graph

Edit this section

QwikBundleGraph

Bundle graph.

Format: [ 'bundle-a.js', 3, 5 // Depends on 'bundle-b.js' and 'bundle-c.js' 'bundle-b.js', 5, // Depends on 'bundle-c.js' 'bundle-c.js', ]

export type QwikBundleGraph = Array<string | number>;

Edit this section

QwikManifest

The metadata of the build. One of its uses is storing where QRL symbols are located.

export interface QwikManifest

Property

Modifiers

Type

Description

assets?

{ [fileName: string]: QwikAsset; }

(Optional) All assets. The key is the fileName relative to the rootDir

bundleGraph?

QwikBundleGraph

(Optional) All bundles in a compact graph format with probabilities

bundleGraphAsset?

string

(Optional) The bundle graph fileName

bundles

{ [fileName: string]: QwikBundle; }

All code bundles, used to know the import graph. The key is the bundle fileName relative to "build/"

core?

string

(Optional) The Qwik core bundle fileName

injections?

GlobalInjections[]

(Optional) CSS etc to inject in the document head

manifestHash

string

Content hash of the manifest, if this changes, the code changed

mapping

{ [symbolName: string]: string; }

Where QRLs are located. The key is the symbol name, the value is the bundle fileName

options?

{ target?: string; buildMode?: string; entryStrategy?: { type: EntryStrategy['type']; }; }

(Optional) The options used to build the manifest

platform?

{ [name: string]: string; }

(Optional) The platform used to build the manifest

preloader?

string

(Optional) The preloader bundle fileName

qwikLoader?

string

(Optional) The Qwik loader bundle fileName

symbols

{ [symbolName: string]: QwikSymbol; }

QRL symbols

version

string

The version of the manifest

Edit this section

qwikRolldown

export declare function qwikRolldown(
  qwikRolldownOpts?: QwikRolldownPluginOptions,
): any;

Parameter

Type

Description

qwikRolldownOpts

QwikRolldownPluginOptions

(Optional)

Returns:

any

Edit this section

QwikRolldownPluginOptions

export interface QwikRolldownPluginOptions

Property

Modifiers

Type

Description

buildMode?

QwikBuildMode

(Optional) Build production or development.

Default development

csr?

boolean

(Optional)

debug?

boolean

(Optional) Prints verbose Qwik plugin debug logs.

Default false

entryStrategy?

EntryStrategy

(Optional) The Qwik entry strategy to use while building for production. During development the type is always segment.

Default { type: "smart" })

experimental?

(keyof typeof ExperimentalFeatures)[]

(Optional) Experimental features. These can come and go in patch releases, and their API is not guaranteed to be stable between releases.

lint?

boolean

(Optional) Run eslint on the source files for the ssr build or dev server. This can slow down startup on large projects. Defaults to true

manifestInput?

QwikManifest

(Optional) The SSR build requires the manifest generated during the client build. The manifestInput option can be used to manually provide a manifest.

Default undefined

manifestOutput?

(manifest: QwikManifest) => Promise<void> | void

(Optional) The client build will create a manifest and this hook is called with the generated build data.

Default undefined

optimizerOptions?

OptimizerOptions

(Optional)

rootDir?

string

(Optional) The root of the application, which is commonly the same directory as package.json and rollup.config.js.

Default process.cwd()

srcDir?

string

(Optional) The source directory to find all the Qwik components. Since Qwik does not have a single input, the srcDir is used to recursively find Qwik files.

Default src

srcInputs?

TransformModuleInput[] | null

(Optional) Alternative to srcDir, where srcInputs is able to provide the files manually. This option is useful for an environment without a file system, such as a webworker.

Default: null

target?

QwikBuildTarget

(Optional) Target client or ssr.

Default client

transformedModuleOutput?

((transformedModules: TransformModule[]) => Promise<void> | void) | null

(Optional) Hook that's called after the build and provides all of the transformed modules that were used before bundling.

Edit this section

qwikRollup

Warning: This API is now obsolete.

Use qwikRolldown.

Renamed to qwikRolldown.

qwikRollup: typeof qwikRolldown;

Edit this section

QwikRollupPluginOptions

Warning: This API is now obsolete.

Use QwikRolldownPluginOptions.

Renamed to QwikRolldownPluginOptions.

export type QwikRollupPluginOptions = QwikRolldownPluginOptions;

References: QwikRolldownPluginOptions

Edit this section

QwikSymbol

export interface QwikSymbol

Property

Modifiers

Type

Description

canonicalFilename

string

captureNames?

string[]

(Optional) The transformed names of scoped variables, if any

captures

boolean

Whether the symbol captures a variable

ctxKind

'function' | 'eventHandler'

ctxName

string

displayName

string

hash

string

loc

[number, number]

origin

string

paramNames?

string[]

(Optional) The parameter names if it's a function with parameters

parent

string | null

Edit this section

qwikVite

The types for Vite/Rolldown don't allow us to be too specific about the return type. The correct return type is [QwikVitePlugin, VitePlugin<never>], and if you search the plugin by name you'll get the QwikVitePlugin.

export declare function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;

Parameter

Type

Description

qwikViteOpts

QwikVitePluginOptions

(Optional)

Returns:

any

Edit this section

QwikVitePlugin

This is the type of the "pre" Qwik Vite plugin. qwikVite actually returns a tuple of two plugins, but after Vite flattens them, you can find the plugin by name.

export type QwikVitePlugin = P<QwikVitePluginApi> & {
  name: "vite-plugin-qwik";
};

References: QwikVitePluginApi

Edit this section

QwikVitePluginApi

export interface QwikVitePluginApi

Property

Modifiers

Type

Description

getClientOutDir

() => string | null

getClientPublicOutDir

() => string | null

getManifest

() => QwikManifest | null

getOptimizer

() => Optimizer | null

getOptions

() => NormalizedQwikPluginOptions

getRootDir

() => string | null

onSegment

(callback: SegmentCallback) => void

Register a callback that fires for each segment emitted during transform.

registerBundleGraphAdder

(adder: BundleGraphAdder) => void

Edit this section

QwikVitePluginOptions

export type QwikVitePluginOptions =
  | QwikVitePluginCSROptions
  | QwikVitePluginSSROptions;

Edit this section

relative

relative(from: string, to: string): string;

Parameter

Type

Description

from

string

to

string

Returns:

string

resolve

resolve(...paths: string[]): string;

Parameter

Type

Description

paths

string[]

Returns:

string

ResolvedManifest

export interface ResolvedManifest

Property

Modifiers

Type

Description

bundleGraph?

QwikBundleGraph

(Optional)

injections?

GlobalInjections[]

(Optional)

manifest

ServerQwikManifest

mapper

SymbolMapper

Edit this section

SegmentAnalysis

export interface SegmentAnalysis

Property

Modifiers

Type

Description

canonicalFilename

string

captureNames?

string[]

(Optional) The transformed names of scoped variables, if any

captures

boolean

ctxKind

'eventHandler' | 'function'

ctxName

string

displayName

string

entry

string | null

extension

string

hash

string

loc

[number, number]

name

string

origin

string

paramNames?

string[]

(Optional) The parameter names if it's a function with parameters

parent

string | null

SegmentEntryStrategy

export interface SegmentEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'segment'

ServerQwikManifest

The manifest values that are needed for SSR.

export type ServerQwikManifest = Pick<
  QwikManifest,
  | "manifestHash"
  | "injections"
  | "bundleGraph"
  | "bundleGraphAsset"
  | "mapping"
  | "preloader"
  | "core"
  | "qwikLoader"
>;

References: QwikManifest

Edit this section

show

SingleEntryStrategy

export interface SingleEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'single'

SmartEntryStrategy

export interface SmartEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'smart'

SourceLocation

export interface SourceLocation

Property

Modifiers

Type

Description

endCol

number

endLine

number

hi

number

lo

number

startCol

number

startLine

number

suspense

SymbolMapper

export type SymbolMapper = Record<
  string,
  readonly [symbol: string, chunk: string]
>;

Edit this section

SymbolMapperFn

export type SymbolMapperFn = (
  symbolName: string,
  mapper: SymbolMapper | undefined,
  parent?: string,
) => readonly [symbol: string, chunk: string] | undefined;

References: SymbolMapper

Edit this section

SystemEnvironment

export type SystemEnvironment =
  | "node"
  | "deno"
  | "bun"
  | "webworker"
  | "browsermain"
  | "unknown";

TransformModule

export interface TransformModule

Property

Modifiers

Type

Description

code

string

imports?

string[]

(Optional)

isEntry

boolean

map

string | null

origPath

string | null

path

string

segment

SegmentAnalysis | null

TransformModuleInput

export interface TransformModuleInput

Property

Modifiers

Type

Description

code

string

devPath?

string

(Optional)

path

string

transformModules

Transforms the input code string, does not access the file system.

transformModules(opts: TransformModulesOptions): Promise<TransformOutput>;

Parameter

Type

Description

opts

TransformModulesOptions

Returns:

Promise<TransformOutput>

TransformModulesOptions

export interface TransformModulesOptions extends TransformOptions

Extends: TransformOptions

Property

Modifiers

Type

Description

input

TransformModuleInput[]

TransformOptions

export interface TransformOptions

Property

Modifiers

Type

Description

entryStrategy?

EntryStrategy

(Optional)

explicitExtensions?

boolean

(Optional)

isServer?

boolean

(Optional)

minify?

MinifyMode

(Optional)

mode?

EmitMode

(Optional)

preserveFilenames?

boolean

(Optional)

regCtxName?

string[]

(Optional)

rootDir?

string

(Optional)

scope?

string

(Optional)

sourceMaps?

boolean

(Optional)

srcDir

string

stripCtxName?

string[]

(Optional)

stripEventHandlers?

boolean

(Optional)

stripExports?

string[]

(Optional)

transpileJsx?

boolean

(Optional)

transpileTs?

boolean

(Optional)

TransformOutput

export interface TransformOutput

Property

Modifiers

Type

Description

diagnostics

Diagnostic[]

isJsx

boolean

isTypeScript

boolean

modules

TransformModule[]

valibot