API › @builder.io/qwik/optimizer

basename

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

參數

類型

說明

path

string

ext

string

(可選)

string

ComponentEntryStrategy

export interface ComponentEntryStrategy

屬性

修飾符

類型

說明

manual?

Record<string, string>

(可選)

type

'component'

編輯此區塊

createOptimizer

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

參數

類型

說明

optimizerOptions

OptimizerOptions

(可選)

Promise<Optimizer>

編輯此區塊

Diagnostic

export interface Diagnostic

屬性

修飾符

類型

說明

category

DiagnosticCategory

code

string | null

file

string

highlights

SourceLocation[]

message

string

scope

string

suggestions

string[] | null

編輯此區塊

DiagnosticCategory

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

編輯此區塊

dirname

dirname(path: string): string;

參數

類型

說明

path

string

string

EntryStrategy

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

參考: InlineEntryStrategy, SingleEntryStrategy, HookEntryStrategy, ComponentEntryStrategy, SmartEntryStrategy

編輯此區塊

extname

extname(path: string): string;

參數

類型

說明

path

string

string

format

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

參數

類型

說明

pathObject

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

string

GlobalInjections

export interface GlobalInjections

屬性

修飾符

類型

說明

attributes?

{ [key: string]: string; }

(可選)

location

'head' | 'body'

tag

string

編輯此區塊

HookAnalysis

export interface HookAnalysis

屬性

修飾符

類型

說明

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

編輯此區塊

HookEntryStrategy

export interface HookEntryStrategy

屬性

修飾符

類型

說明

manual?

Record<string, string>

(可選)

type

'hook'

編輯此區塊

InlineEntryStrategy

export interface InlineEntryStrategy

屬性

修飾符

類型

說明

type

'inline'

編輯此區塊

InsightManifest

export interface InsightManifest

屬性

修飾符

類型

說明

manual

Record<string, string>

prefetch

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

type

'smart'

編輯此區塊

isAbsolute

isAbsolute(path: string): boolean;

參數

類型

說明

path

string

boolean

join

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

參數

類型

說明

paths

string[]

string

MinifyMode

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

編輯此區塊

normalize

normalize(path: string): string;

參數

類型

說明

path

string

string

Optimizer

export interface Optimizer

屬性

修飾符

類型

說明

sys

優化器系統

優化器系統的使用。這可以透過自訂檔案系統更新。

方法

說明

transformFs(opts)

從檔案系統轉換目錄。

transformFsSync(opts)

從檔案系統轉換目錄。

transformModules(opts)

轉換輸入的程式碼字串,不訪問檔案系統。

transformModulesSync(opts)

轉換輸入的程式碼字串,不訪問檔案系統。

編輯此區塊

優化器選項

export interface OptimizerOptions

屬性

修飾符

類型

說明

binding?

任何

(可選)

inlineStylesUpToBytes?

數字

(可選) 如果全域樣式小於此值,則將其內嵌

sourcemap?

boolean

(可選) 啟用來源映射

sys?

優化器系統

(可選)

編輯此區塊

優化器系統

export interface OptimizerSystem

屬性

修飾符

類型

說明

cwd

() => 字串

dynamicImport

(path: 字串) => Promise<任何>

env

系統環境

getInputFiles?

(rootDir: 字串) => Promise<轉換模組輸入[]>

(可選)

os

string

path

路徑

strictDynamicImport

(path: 字串) => Promise<任何>

編輯此區塊

解析

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

參數

類型

說明

path

string

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

路徑

export interface Path

屬性

修飾符

類型

說明

分隔符號

唯讀

string

posix

唯讀

路徑

分隔符號

唯讀

string

win32

唯讀

方法

說明

basename(path, ext)

dirname(path)

extname(path)

format(pathObject)

isAbsolute(path)

join(paths)

normalize(path)

parse(path)

relative(from, to)

resolve(paths)

編輯此區塊

Qwik 建置模式

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

編輯此區塊

Qwik 建置目標

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

編輯此區塊

Qwik 套件

export interface QwikBundle

屬性

修飾符

類型

說明

dynamicImports?

string[]

(可選)

imports?

string[]

(可選)

origins?

string[]

(可選)

大小

數字

symbols?

string[]

(可選)

編輯此區塊

Qwik 資訊清單

建置的詮釋資料。其中一個用途是儲存 QRL 符號的位置。

export interface QwikManifest

屬性

修飾符

類型

說明

套件

{ [fileName: 字串]: Qwik 套件; }

所有程式碼套件,用於了解匯入圖

injections?

全域注入[]

(可選) 要注入文件標頭的 CSS 等

manifestHash

string

資訊清單的內容雜湊,如果這改變了,表示程式碼也改變了

mapping

{ [symbolName: 字串]: 字串; }

QRL 的位置

options?

{ target?: 字串; buildMode?: 字串; entryStrategy?: { [key: 字串]: 任何; }; }

(可選)

platform?

{ [name: 字串]: 字串; }

(可選)

symbols

{ [symbolName: 字串]: Qwik 符號; }

QRL 符號

版本

string

編輯此區塊

qwikRollup

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

參數

類型

說明

qwikRollupOpts

QwikRollupPluginOptions

(可選)

任何

編輯此區塊

QwikRollupPluginOptions

export interface QwikRollupPluginOptions

屬性

修飾符

類型

說明

buildMode?

Qwik 建置模式

(可選) 建置 productiondevelopment

預設 development

csr?

boolean

(可選)

debug?

boolean

(可選) 印出詳細的 Qwik 外掛偵錯日誌。

預設 false

entryStrategy?

進入策略

(可選) 在建置生產環境時要使用的 Qwik 進入策略。在開發過程中,類型始終為 hook

預設 { type: "smart" })

lint?

boolean

(可選) 對 ssr 建置或開發伺服器的原始檔執行 eslint。這可能會降低大型專案的啟動速度。預設為 true

manifestInput?

Qwik 資訊清單

(可選) SSR 建置需要在用戶端建置期間產生的資訊清單。可以使用 manifestInput 選項手動提供資訊清單。

預設 undefined

manifestOutput?

(manifest: Qwik 資訊清單) => Promise<void> | void

(可選) 用戶端建置將建立一個資訊清單,並使用產生的建置資料呼叫此鉤子。

預設 undefined

optimizerOptions?

OptimizerOptions

(可選)

rootDir?

string

(可選)應用程式的根目錄,通常與 package.jsonrollup.config.js 位於相同目錄。

預設值 process.cwd()

srcDir?

string

(可選)用於尋找所有 Qwik 組件的原始碼目錄。由於 Qwik 沒有單一輸入,因此使用 srcDir 遞迴尋找 Qwik 檔案。

預設值 src

srcInputs?

TransformModuleInput[] | null

(可選)srcDir 的替代方案,其中 srcInputs 能夠手動提供檔案。此選項適用於沒有檔案系統的環境,例如 webworker。

預設值:null

target?

QwikBuildTarget

(可選)目標 clientssr

預設值 client

transformedModuleOutput?

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

(可選)在構建後呼叫的鉤子,提供在捆綁之前使用的所有已轉換模組。

編輯此區塊

QwikSymbol

export interface QwikSymbol

屬性

修飾符

類型

說明

canonicalFilename

string

captures

boolean

ctxKind

'function' | 'event'

ctxName

string

displayName

string

hash

string

loc

[number, number]

origin

string

parent

string | null

編輯此區塊

qwikVite

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

參數

類型

說明

qwikViteOpts

QwikVitePluginOptions

(可選)

任何

編輯此區塊

QwikViteDevResponse

export interface QwikViteDevResponse

屬性

修飾符

類型

說明

_qwikEnvData?

Record<string, any>

(可選)

_qwikRenderResolve?

() => void

(可選)

編輯此區塊

QwikVitePlugin

export interface QwikVitePlugin

屬性

修飾符

類型

說明

api

QwikVitePluginApi

name

'vite-plugin-qwik'

編輯此區塊

QwikVitePluginApi

export interface QwikVitePluginApi

屬性

修飾符

類型

說明

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

編輯此區塊

QwikVitePluginOptions

export type QwikVitePluginOptions =
  | QwikVitePluginCSROptions
  | QwikVitePluginSSROptions;

編輯此區塊

relative

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

參數

類型

說明

from

string

to

string

string

resolve

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

參數

類型

說明

paths

string[]

string

ResolvedManifest

export interface ResolvedManifest

屬性

修飾符

類型

說明

manifest

Qwik 資訊清單

mapper

SymbolMapper

編輯此區塊

SingleEntryStrategy

export interface SingleEntryStrategy

屬性

修飾符

類型

說明

manual?

Record<string, string>

(可選)

type

'single'

編輯此區塊

SmartEntryStrategy

export interface SmartEntryStrategy

屬性

修飾符

類型

說明

manual?

Record<string, string>

(可選)

type

'smart'

編輯此區塊

SourceLocation

export interface SourceLocation

屬性

修飾符

類型

說明

endCol

數字

endLine

數字

hi

數字

lo

數字

startCol

數字

startLine

數字

編輯此區塊

SourceMapsOption

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

編輯此區塊

symbolMapper

此 API 作為 Alpha 預覽版提供給開發人員,可能會根據我們收到的回饋而變更。請勿在生產環境中使用此 API。

對於給定的符號(QRL,例如 onKeydown$),伺服器需要知道符號所在的捆綁包。

通常這是由 Qwik 的 q-manifest 提供的。但 q-manifest 僅在完整的客戶端構建後才存在。

這在開發模式中會是個問題。因此,在開發模式中,符號會使用下面的 symbolMapper 函數映射到預期的 URL。對於 Vite,給定符號的路徑是固定的。

symbolMapper: ReturnType<typeof createSymbolMapper>;

編輯此區塊

SymbolMapper

此 API 作為 Alpha 預覽版提供給開發人員,可能會根據我們收到的回饋而變更。請勿在生產環境中使用此 API。

對於給定的符號(QRL,例如 onKeydown$),伺服器需要知道符號所在的捆綁包。

通常這是由 Qwik 的 q-manifest 提供的。但 q-manifest 僅在完整的客戶端構建後才存在。

這在開發模式中會是個問題。因此,在開發模式中,符號會使用下面的 symbolMapper 函數映射到預期的 URL。對於 Vite,給定符號的路徑是固定的。

symbolMapper: ReturnType<typeof createSymbolMapper>;

編輯此區塊

SymbolMapperFn

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

參考: SymbolMapper

編輯此區塊

系統環境

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

編輯此區塊

transformFs

從檔案系統轉換目錄。

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

參數

類型

說明

選項

TransformFs 選項

Promise<TransformOutput>

TransformFs 選項

export interface TransformFsOptions extends TransformOptions

擴展: Transform 選項

屬性

修飾符

類型

說明

供應商根目錄

string[]

編輯此區塊

transformFsSync

從檔案系統轉換目錄。

transformFsSync(opts: TransformFsOptions): TransformOutput;

參數

類型

說明

選項

TransformFs 選項

Transform 輸出

Transform 模組

export interface TransformModule

屬性

修飾符

類型

說明

code

string

鉤子

鉤子分析 | null

是否為入口

boolean

映射

string | null

原始路徑

string | null

path

string

編輯此區塊

Transform 模組輸入

export interface TransformModuleInput

屬性

修飾符

類型

說明

code

string

path

string

編輯此區塊

transformModules

轉換輸入的程式碼字串,不訪問檔案系統。

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

參數

類型

說明

選項

TransformModules 選項

Promise<TransformOutput>

TransformModules 選項

export interface TransformModulesOptions extends TransformOptions

擴展: Transform 選項

屬性

修飾符

類型

說明

輸入

Transform 模組輸入[]

編輯此區塊

transformModulesSync

轉換輸入的程式碼字串,不訪問檔案系統。

transformModulesSync(opts: TransformModulesOptions): TransformOutput;

參數

類型

說明

選項

TransformModules 選項

Transform 輸出

Transform 選項

export interface TransformOptions

屬性

修飾符

類型

說明

entryStrategy?

進入策略

(可選)

顯式擴展名?

boolean

(可選)

是否為伺服器端?

boolean

(可選)

是否壓縮?

壓縮模式

(可選)

模式?

發射模式

(可選)

是否保留檔名?

boolean

(可選)

regCtx 名稱?

string[]

(可選)

rootDir?

string

(可選)

作用域?

string

(可選)

來源映射?

boolean

(可選)

來源目錄

string

是否移除 Ctx 名稱?

string[]

(可選)

是否移除事件處理器?

boolean

(可選)

是否移除匯出?

string[]

(可選)

是否轉譯 JSX?

boolean

(可選)

是否轉譯 TS?

boolean

(可選)

編輯此區塊

Transform 輸出

export interface TransformOutput

屬性

修飾符

類型

說明

診斷

診斷[]

是否為 JSX

boolean

是否為 TypeScript

boolean

模組

Transform 模組[]

編輯此區塊

轉譯選項

export type TranspileOption = boolean | undefined | null;

編輯此區塊

版本

versions: {
  qwik: string;
}

編輯此區塊