[6a3a178] | 1 | export type Platform = 'browser' | 'node' | 'neutral';
|
---|
| 2 | export type Format = 'iife' | 'cjs' | 'esm';
|
---|
| 3 | export type Loader = 'js' | 'jsx' | 'ts' | 'tsx' | 'css' | 'json' | 'text' | 'base64' | 'file' | 'dataurl' | 'binary' | 'default';
|
---|
| 4 | export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent';
|
---|
| 5 | export type Charset = 'ascii' | 'utf8';
|
---|
| 6 |
|
---|
| 7 | interface CommonOptions {
|
---|
| 8 | sourcemap?: boolean | 'inline' | 'external' | 'both';
|
---|
| 9 | legalComments?: 'none' | 'inline' | 'eof' | 'linked' | 'external';
|
---|
| 10 | sourceRoot?: string;
|
---|
| 11 | sourcesContent?: boolean;
|
---|
| 12 |
|
---|
| 13 | format?: Format;
|
---|
| 14 | globalName?: string;
|
---|
| 15 | target?: string | string[];
|
---|
| 16 |
|
---|
| 17 | minify?: boolean;
|
---|
| 18 | minifyWhitespace?: boolean;
|
---|
| 19 | minifyIdentifiers?: boolean;
|
---|
| 20 | minifySyntax?: boolean;
|
---|
| 21 | charset?: Charset;
|
---|
| 22 | treeShaking?: boolean;
|
---|
| 23 | ignoreAnnotations?: boolean;
|
---|
| 24 |
|
---|
| 25 | jsx?: 'transform' | 'preserve';
|
---|
| 26 | jsxFactory?: string;
|
---|
| 27 | jsxFragment?: string;
|
---|
| 28 |
|
---|
| 29 | define?: { [key: string]: string };
|
---|
| 30 | pure?: string[];
|
---|
| 31 | keepNames?: boolean;
|
---|
| 32 |
|
---|
| 33 | color?: boolean;
|
---|
| 34 | logLevel?: LogLevel;
|
---|
| 35 | logLimit?: number;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | export interface BuildOptions extends CommonOptions {
|
---|
| 39 | bundle?: boolean;
|
---|
| 40 | splitting?: boolean;
|
---|
| 41 | preserveSymlinks?: boolean;
|
---|
| 42 | outfile?: string;
|
---|
| 43 | metafile?: boolean;
|
---|
| 44 | outdir?: string;
|
---|
| 45 | outbase?: string;
|
---|
| 46 | platform?: Platform;
|
---|
| 47 | external?: string[];
|
---|
| 48 | loader?: { [ext: string]: Loader };
|
---|
| 49 | resolveExtensions?: string[];
|
---|
| 50 | mainFields?: string[];
|
---|
| 51 | conditions?: string[];
|
---|
| 52 | write?: boolean;
|
---|
| 53 | allowOverwrite?: boolean;
|
---|
| 54 | tsconfig?: string;
|
---|
| 55 | outExtension?: { [ext: string]: string };
|
---|
| 56 | publicPath?: string;
|
---|
| 57 | entryNames?: string;
|
---|
| 58 | chunkNames?: string;
|
---|
| 59 | assetNames?: string;
|
---|
| 60 | inject?: string[];
|
---|
| 61 | banner?: { [type: string]: string };
|
---|
| 62 | footer?: { [type: string]: string };
|
---|
| 63 | incremental?: boolean;
|
---|
| 64 | entryPoints?: string[] | Record<string, string>;
|
---|
| 65 | stdin?: StdinOptions;
|
---|
| 66 | plugins?: Plugin[];
|
---|
| 67 | absWorkingDir?: string;
|
---|
| 68 | nodePaths?: string[]; // The "NODE_PATH" variable from Node.js
|
---|
| 69 | watch?: boolean | WatchMode;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | export interface WatchMode {
|
---|
| 73 | onRebuild?: (error: BuildFailure | null, result: BuildResult | null) => void;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | export interface StdinOptions {
|
---|
| 77 | contents: string;
|
---|
| 78 | resolveDir?: string;
|
---|
| 79 | sourcefile?: string;
|
---|
| 80 | loader?: Loader;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | export interface Message {
|
---|
| 84 | pluginName: string;
|
---|
| 85 | text: string;
|
---|
| 86 | location: Location | null;
|
---|
| 87 | notes: Note[];
|
---|
| 88 |
|
---|
| 89 | // Optional user-specified data that is passed through unmodified. You can
|
---|
| 90 | // use this to stash the original error, for example.
|
---|
| 91 | detail: any;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | export interface Note {
|
---|
| 95 | text: string;
|
---|
| 96 | location: Location | null;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | export interface Location {
|
---|
| 100 | file: string;
|
---|
| 101 | namespace: string;
|
---|
| 102 | line: number; // 1-based
|
---|
| 103 | column: number; // 0-based, in bytes
|
---|
| 104 | length: number; // in bytes
|
---|
| 105 | lineText: string;
|
---|
| 106 | suggestion: string;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | export interface OutputFile {
|
---|
| 110 | path: string;
|
---|
| 111 | contents: Uint8Array; // "text" as bytes
|
---|
| 112 | text: string; // "contents" as text
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | export interface BuildInvalidate {
|
---|
| 116 | (): Promise<BuildIncremental>;
|
---|
| 117 | dispose(): void;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | export interface BuildIncremental extends BuildResult {
|
---|
| 121 | rebuild: BuildInvalidate;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | export interface BuildResult {
|
---|
| 125 | errors: Message[];
|
---|
| 126 | warnings: Message[];
|
---|
| 127 | outputFiles?: OutputFile[]; // Only when "write: false"
|
---|
| 128 | rebuild?: BuildInvalidate; // Only when "incremental: true"
|
---|
| 129 | stop?: () => void; // Only when "watch: true"
|
---|
| 130 | metafile?: Metafile; // Only when "metafile: true"
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | export interface BuildFailure extends Error {
|
---|
| 134 | errors: Message[];
|
---|
| 135 | warnings: Message[];
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | export interface ServeOptions {
|
---|
| 139 | port?: number;
|
---|
| 140 | host?: string;
|
---|
| 141 | servedir?: string;
|
---|
| 142 | onRequest?: (args: ServeOnRequestArgs) => void;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | export interface ServeOnRequestArgs {
|
---|
| 146 | remoteAddress: string;
|
---|
| 147 | method: string;
|
---|
| 148 | path: string;
|
---|
| 149 | status: number;
|
---|
| 150 | timeInMS: number; // The time to generate the response, not to send it
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | export interface ServeResult {
|
---|
| 154 | port: number;
|
---|
| 155 | host: string;
|
---|
| 156 | wait: Promise<void>;
|
---|
| 157 | stop: () => void;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | export interface TransformOptions extends CommonOptions {
|
---|
| 161 | tsconfigRaw?: string | {
|
---|
| 162 | compilerOptions?: {
|
---|
| 163 | jsxFactory?: string,
|
---|
| 164 | jsxFragmentFactory?: string,
|
---|
| 165 | useDefineForClassFields?: boolean,
|
---|
| 166 | importsNotUsedAsValues?: 'remove' | 'preserve' | 'error',
|
---|
| 167 | },
|
---|
| 168 | };
|
---|
| 169 |
|
---|
| 170 | sourcefile?: string;
|
---|
| 171 | loader?: Loader;
|
---|
| 172 | banner?: string;
|
---|
| 173 | footer?: string;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | export interface TransformResult {
|
---|
| 177 | code: string;
|
---|
| 178 | map: string;
|
---|
| 179 | warnings: Message[];
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | export interface TransformFailure extends Error {
|
---|
| 183 | errors: Message[];
|
---|
| 184 | warnings: Message[];
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | export interface Plugin {
|
---|
| 188 | name: string;
|
---|
| 189 | setup: (build: PluginBuild) => (void | Promise<void>);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | export interface PluginBuild {
|
---|
| 193 | initialOptions: BuildOptions;
|
---|
| 194 | onStart(callback: () =>
|
---|
| 195 | (OnStartResult | null | void | Promise<OnStartResult | null | void>)): void;
|
---|
| 196 | onEnd(callback: (result: BuildResult) =>
|
---|
| 197 | (void | Promise<void>)): void;
|
---|
| 198 | onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
|
---|
| 199 | (OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void;
|
---|
| 200 | onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
|
---|
| 201 | (OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>)): void;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | export interface OnStartResult {
|
---|
| 205 | errors?: PartialMessage[];
|
---|
| 206 | warnings?: PartialMessage[];
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | export interface OnResolveOptions {
|
---|
| 210 | filter: RegExp;
|
---|
| 211 | namespace?: string;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | export interface OnResolveArgs {
|
---|
| 215 | path: string;
|
---|
| 216 | importer: string;
|
---|
| 217 | namespace: string;
|
---|
| 218 | resolveDir: string;
|
---|
| 219 | kind: ImportKind;
|
---|
| 220 | pluginData: any;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | export type ImportKind =
|
---|
| 224 | | 'entry-point'
|
---|
| 225 |
|
---|
| 226 | // JS
|
---|
| 227 | | 'import-statement'
|
---|
| 228 | | 'require-call'
|
---|
| 229 | | 'dynamic-import'
|
---|
| 230 | | 'require-resolve'
|
---|
| 231 |
|
---|
| 232 | // CSS
|
---|
| 233 | | 'import-rule'
|
---|
| 234 | | 'url-token'
|
---|
| 235 |
|
---|
| 236 | export interface OnResolveResult {
|
---|
| 237 | pluginName?: string;
|
---|
| 238 |
|
---|
| 239 | errors?: PartialMessage[];
|
---|
| 240 | warnings?: PartialMessage[];
|
---|
| 241 |
|
---|
| 242 | path?: string;
|
---|
| 243 | external?: boolean;
|
---|
| 244 | sideEffects?: boolean;
|
---|
| 245 | namespace?: string;
|
---|
| 246 | pluginData?: any;
|
---|
| 247 |
|
---|
| 248 | watchFiles?: string[];
|
---|
| 249 | watchDirs?: string[];
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | export interface OnLoadOptions {
|
---|
| 253 | filter: RegExp;
|
---|
| 254 | namespace?: string;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | export interface OnLoadArgs {
|
---|
| 258 | path: string;
|
---|
| 259 | namespace: string;
|
---|
| 260 | pluginData: any;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | export interface OnLoadResult {
|
---|
| 264 | pluginName?: string;
|
---|
| 265 |
|
---|
| 266 | errors?: PartialMessage[];
|
---|
| 267 | warnings?: PartialMessage[];
|
---|
| 268 |
|
---|
| 269 | contents?: string | Uint8Array;
|
---|
| 270 | resolveDir?: string;
|
---|
| 271 | loader?: Loader;
|
---|
| 272 | pluginData?: any;
|
---|
| 273 |
|
---|
| 274 | watchFiles?: string[];
|
---|
| 275 | watchDirs?: string[];
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | export interface PartialMessage {
|
---|
| 279 | pluginName?: string;
|
---|
| 280 | text?: string;
|
---|
| 281 | location?: Partial<Location> | null;
|
---|
| 282 | notes?: PartialNote[];
|
---|
| 283 | detail?: any;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | export interface PartialNote {
|
---|
| 287 | text?: string;
|
---|
| 288 | location?: Partial<Location> | null;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | export interface Metafile {
|
---|
| 292 | inputs: {
|
---|
| 293 | [path: string]: {
|
---|
| 294 | bytes: number
|
---|
| 295 | imports: {
|
---|
| 296 | path: string
|
---|
| 297 | kind: ImportKind
|
---|
| 298 | }[]
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 | outputs: {
|
---|
| 302 | [path: string]: {
|
---|
| 303 | bytes: number
|
---|
| 304 | inputs: {
|
---|
| 305 | [path: string]: {
|
---|
| 306 | bytesInOutput: number
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 | imports: {
|
---|
| 310 | path: string
|
---|
| 311 | kind: ImportKind
|
---|
| 312 | }[]
|
---|
| 313 | exports: string[]
|
---|
| 314 | entryPoint?: string
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | export interface FormatMessagesOptions {
|
---|
| 320 | kind: 'error' | 'warning';
|
---|
| 321 | color?: boolean;
|
---|
| 322 | terminalWidth?: number;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | export interface AnalyzeMetafileOptions {
|
---|
| 326 | color?: boolean;
|
---|
| 327 | verbose?: boolean;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | // This function invokes the "esbuild" command-line tool for you. It returns a
|
---|
| 331 | // promise that either resolves with a "BuildResult" object or rejects with a
|
---|
| 332 | // "BuildFailure" object.
|
---|
| 333 | //
|
---|
| 334 | // Works in node: yes
|
---|
| 335 | // Works in browser: yes
|
---|
| 336 | export declare function build(options: BuildOptions & { write: false }): Promise<BuildResult & { outputFiles: OutputFile[] }>;
|
---|
| 337 | export declare function build(options: BuildOptions & { incremental: true }): Promise<BuildIncremental>;
|
---|
| 338 | export declare function build(options: BuildOptions): Promise<BuildResult>;
|
---|
| 339 |
|
---|
| 340 | // This function is similar to "build" but it serves the resulting files over
|
---|
| 341 | // HTTP on a localhost address with the specified port.
|
---|
| 342 | //
|
---|
| 343 | // Works in node: yes
|
---|
| 344 | // Works in browser: no
|
---|
| 345 | export declare function serve(serveOptions: ServeOptions, buildOptions: BuildOptions): Promise<ServeResult>;
|
---|
| 346 |
|
---|
| 347 | // This function transforms a single JavaScript file. It can be used to minify
|
---|
| 348 | // JavaScript, convert TypeScript/JSX to JavaScript, or convert newer JavaScript
|
---|
| 349 | // to older JavaScript. It returns a promise that is either resolved with a
|
---|
| 350 | // "TransformResult" object or rejected with a "TransformFailure" object.
|
---|
| 351 | //
|
---|
| 352 | // Works in node: yes
|
---|
| 353 | // Works in browser: yes
|
---|
| 354 | export declare function transform(input: string, options?: TransformOptions): Promise<TransformResult>;
|
---|
| 355 |
|
---|
| 356 | // Converts log messages to formatted message strings suitable for printing in
|
---|
| 357 | // the terminal. This allows you to reuse the built-in behavior of esbuild's
|
---|
| 358 | // log message formatter. This is a batch-oriented API for efficiency.
|
---|
| 359 | //
|
---|
| 360 | // Works in node: yes
|
---|
| 361 | // Works in browser: yes
|
---|
| 362 | export declare function formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>;
|
---|
| 363 |
|
---|
| 364 | // Pretty-prints an analysis of the metafile JSON to a string. This is just for
|
---|
| 365 | // convenience to be able to match esbuild's pretty-printing exactly. If you want
|
---|
| 366 | // to customize it, you can just inspect the data in the metafile yourself.
|
---|
| 367 | //
|
---|
| 368 | // Works in node: yes
|
---|
| 369 | // Works in browser: yes
|
---|
| 370 | export declare function analyzeMetafile(metafile: Metafile | string, options?: AnalyzeMetafileOptions): Promise<string>;
|
---|
| 371 |
|
---|
| 372 | // A synchronous version of "build".
|
---|
| 373 | //
|
---|
| 374 | // Works in node: yes
|
---|
| 375 | // Works in browser: no
|
---|
| 376 | export declare function buildSync(options: BuildOptions & { write: false }): BuildResult & { outputFiles: OutputFile[] };
|
---|
| 377 | export declare function buildSync(options: BuildOptions): BuildResult;
|
---|
| 378 |
|
---|
| 379 | // A synchronous version of "transform".
|
---|
| 380 | //
|
---|
| 381 | // Works in node: yes
|
---|
| 382 | // Works in browser: no
|
---|
| 383 | export declare function transformSync(input: string, options?: TransformOptions): TransformResult;
|
---|
| 384 |
|
---|
| 385 | // A synchronous version of "formatMessages".
|
---|
| 386 | //
|
---|
| 387 | // Works in node: yes
|
---|
| 388 | // Works in browser: no
|
---|
| 389 | export declare function formatMessagesSync(messages: PartialMessage[], options: FormatMessagesOptions): string[];
|
---|
| 390 |
|
---|
| 391 | // A synchronous version of "analyzeMetafile".
|
---|
| 392 | //
|
---|
| 393 | // Works in node: yes
|
---|
| 394 | // Works in browser: no
|
---|
| 395 | export declare function analyzeMetafileSync(metafile: Metafile | string, options?: AnalyzeMetafileOptions): string;
|
---|
| 396 |
|
---|
| 397 | // This configures the browser-based version of esbuild. It is necessary to
|
---|
| 398 | // call this first and wait for the returned promise to be resolved before
|
---|
| 399 | // making other API calls when using esbuild in the browser.
|
---|
| 400 | //
|
---|
| 401 | // Works in node: yes
|
---|
| 402 | // Works in browser: yes ("options" is required)
|
---|
| 403 | export declare function initialize(options: InitializeOptions): Promise<void>;
|
---|
| 404 |
|
---|
| 405 | export interface InitializeOptions {
|
---|
| 406 | // The URL of the "esbuild.wasm" file. This must be provided when running
|
---|
| 407 | // esbuild in the browser.
|
---|
| 408 | wasmURL?: string
|
---|
| 409 |
|
---|
| 410 | // By default esbuild runs the WebAssembly-based browser API in a web worker
|
---|
| 411 | // to avoid blocking the UI thread. This can be disabled by setting "worker"
|
---|
| 412 | // to false.
|
---|
| 413 | worker?: boolean
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | export let version: string;
|
---|