API โ€บ @builder.io/qwik/optimizer

basename

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

Parameter

Type

Description

path

string

ext

string

(Optional)

string

ComponentEntryStrategy

export interface ComponentEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'component'

Edit this section

createOptimizer

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

Parameter

Type

Description

optimizerOptions

OptimizerOptions

(Optional)

Promise<Optimizer>

Edit this section

Diagnostic

export interface Diagnostic

Property

Modifiers

Type

Description

category

DiagnosticCategory

code

string | null

file

string

highlights

SourceLocation[]

message

string

scope

string

suggestions

string[] | null

Edit this section

DiagnosticCategory

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

Edit this section

dirname

dirname(path: string): string;

Parameter

Type

Description

path

string

string

EntryStrategy

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

References: InlineEntryStrategy, SingleEntryStrategy, SegmentEntryStrategy, ComponentEntryStrategy, SmartEntryStrategy

Edit this section

ExperimentalFeatures

This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

export type ExperimentalFeatures = (typeof experimental)[number];

Edit this section

extname

extname(path: string): string;

Parameter

Type

Description

path

string

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; }

string

GlobalInjections

export interface GlobalInjections

Property

Modifiers

Type

Description

attributes?

{ [key: string]: string; }

(Optional)

location

'head' | 'body'

tag

string

Edit this section

InlineEntryStrategy

export interface InlineEntryStrategy

Property

Modifiers

Type

Description

type

'inline'

Edit this section

InsightManifest

export interface InsightManifest

Property

Modifiers

Type

Description

manual

Record<string, string>

prefetch

{ route: string; symbols: string[]; }[]

type

'smart'

Edit this section

isAbsolute

isAbsolute(path: string): boolean;

Parameter

Type

Description

path

string

boolean

join

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

Parameter

Type

Description

paths

string[]

string

MinifyMode

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

Edit this section

normalize

normalize(path: string): string;

Parameter

Type

Description

path

string

string

Optimizer

export interface Optimizer

Property

Modifiers

Type

Description

sys

OptimizerSystem

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

Method

Description

transformFs(opts)

Transforms the directory from the file system.

transformFsSync(opts)

Transforms the directory from the file system.

transformModules(opts)

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

transformModulesSync(opts)

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

Edit this section

OptimizerOptions

export interface OptimizerOptions

Property

Modifiers

Type

Description

binding?

any

(Optional)

inlineStylesUpToBytes?

number

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

sourcemap?

boolean

(Optional) Enable sourcemaps

sys?

OptimizerSystem

(Optional)

Edit this section

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>

Edit this section

parse

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

Parameter

Type

Description

path

string

{ 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)

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)

imports?

string[]

(Optional)

isTask?

boolean

(Optional) Not precise, but an indication of whether this import may be a task

origins?

string[]

(Optional)

size

number

symbols?

string[]

(Optional)

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

bundles

{ [fileName: string]: QwikBundle; }

All code bundles, used to know the import graph

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

options?

{ target?: string; buildMode?: string; entryStrategy?: { [key: string]: any; }; }

(Optional)

platform?

{ [name: string]: string; }

(Optional)

symbols

{ [symbolName: string]: QwikSymbol; }

QRL symbols

version

string

Edit this section

qwikRollup

export declare function qwikRollup(
  qwikRollupOpts?: QwikRollupPluginOptions,
): any;

Parameter

Type

Description

qwikRollupOpts

QwikRollupPluginOptions

(Optional)

any

Edit this section

QwikRollupPluginOptions

export interface QwikRollupPluginOptions

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?

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

QwikSymbol

export interface QwikSymbol

Property

Modifiers

Type

Description

canonicalFilename

string

captures

boolean

ctxKind

'function' | 'event'

ctxName

string

displayName

string

hash

string

loc

[number, number]

origin

string

parent

string | null

Edit this section

qwikVite

The types for Vite/Rollup 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)

any

Edit this section

QwikViteDevResponse

export interface QwikViteDevResponse

Property

Modifiers

Type

Description

_qwikEnvData?

Record<string, any>

(Optional)

_qwikRenderResolve?

() => void

(Optional)

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

getAssetsDir

() => string | undefined

getClientOutDir

() => string | null

getClientPublicOutDir

() => string | null

getInsightsManifest

(clientOutDir?: string | null) => Promise<InsightManifest | null>

getManifest

() => QwikManifest | null

getOptimizer

() => Optimizer | null

getOptions

() => NormalizedQwikPluginOptions

getRootDir

() => string | null

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

string

resolve

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

Parameter

Type

Description

paths

string[]

string

ResolvedManifest

export interface ResolvedManifest

Property

Modifiers

Type

Description

manifest

QwikManifest

mapper

SymbolMapper

Edit this section

SegmentAnalysis

export interface SegmentAnalysis

Property

Modifiers

Type

Description

canonicalFilename

string

captures

boolean

ctxKind

'event' | 'function'

ctxName

string

displayName

string

entry

string | null

extension

string

hash

string

loc

[number, number]

name

string

origin

string

parent

string | null

Edit this section

SegmentEntryStrategy

export interface SegmentEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'segment'

Edit this section

SingleEntryStrategy

export interface SingleEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'single'

Edit this section

SmartEntryStrategy

export interface SmartEntryStrategy

Property

Modifiers

Type

Description

manual?

Record<string, string>

(Optional)

type

'smart'

Edit this section

SourceLocation

export interface SourceLocation

Property

Modifiers

Type

Description

endCol

number

endLine

number

hi

number

lo

number

startCol

number

startLine

number

Edit this section

SourceMapsOption

export type SourceMapsOption = "external" | "inline" | undefined | null;

Edit this section

symbolMapper

This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

For a given symbol (QRL such as onKeydown$) the server needs to know which bundle the symbol is in.

Normally this is provided by Qwik's q-manifest . But q-manifest only exists after a full client build.

This would be a problem in dev mode. So in dev mode the symbol is mapped to the expected URL using the symbolMapper function below. For Vite the given path is fixed for a given symbol.

symbolMapper: ReturnType<typeof createSymbolMapper>;

Edit this section

SymbolMapper

This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

For a given symbol (QRL such as onKeydown$) the server needs to know which bundle the symbol is in.

Normally this is provided by Qwik's q-manifest . But q-manifest only exists after a full client build.

This would be a problem in dev mode. So in dev mode the symbol is mapped to the expected URL using the symbolMapper function below. For Vite the given path is fixed for a given symbol.

symbolMapper: ReturnType<typeof createSymbolMapper>;

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";

Edit this section

transformFs

Transforms the directory from the file system.

transformFs(opts: TransformFsOptions): Promise<TransformOutput>;

Parameter

Type

Description

opts

TransformFsOptions

Promise<TransformOutput>

TransformFsOptions

export interface TransformFsOptions extends TransformOptions

Extends: TransformOptions

Property

Modifiers

Type

Description

vendorRoots

string[]

Edit this section

transformFsSync

Transforms the directory from the file system.

transformFsSync(opts: TransformFsOptions): TransformOutput;

Parameter

Type

Description

opts

TransformFsOptions

TransformOutput

TransformModule

export interface TransformModule

Property

Modifiers

Type

Description

code

string

isEntry

boolean

map

string | null

origPath

string | null

path

string

segment

SegmentAnalysis | null

Edit this section

TransformModuleInput

export interface TransformModuleInput

Property

Modifiers

Type

Description

code

string

path

string

Edit this section

transformModules

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

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

Parameter

Type

Description

opts

TransformModulesOptions

Promise<TransformOutput>

TransformModulesOptions

export interface TransformModulesOptions extends TransformOptions

Extends: TransformOptions

Property

Modifiers

Type

Description

input

TransformModuleInput[]

Edit this section

transformModulesSync

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

transformModulesSync(opts: TransformModulesOptions): TransformOutput;

Parameter

Type

Description

opts

TransformModulesOptions

TransformOutput

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)

Edit this section

TransformOutput

export interface TransformOutput

Property

Modifiers

Type

Description

diagnostics

Diagnostic[]

isJsx

boolean

isTypeScript

boolean

modules

TransformModule[]

Edit this section

TranspileOption

export type TranspileOption = boolean | undefined | null;

Edit this section

versions

versions: {
  qwik: string;
}

Edit this section