|
1 | 1 | import type { GitCommit } from "changelogen"; |
2 | | -import type { BuildOptions } from "esbuild"; |
| 2 | +import type { BuildOptions as esbuildConfig } from "esbuild"; |
| 3 | +import type { InputOptions, RolldownPluginOption, TransformOptions } from "rolldown"; |
| 4 | +import type { MinifyOptions } from "rolldown/experimental"; |
3 | 5 | import type { LogLevelType } from "../utils/logger.js"; |
4 | 6 | import type { Context } from "./index.js"; |
5 | 7 | import type { Manifest } from "./manifest.js"; |
6 | 8 | import type { UpdateJSON } from "./update-json.js"; |
| 9 | +import type { Arrayable } from "./utils.js"; |
7 | 10 |
|
8 | 11 | export interface Config { |
9 | 12 | /** |
@@ -174,6 +177,58 @@ export interface Config { |
174 | 177 | logLevel: LogLevelType; |
175 | 178 | } |
176 | 179 |
|
| 180 | +export interface BundleItem { |
| 181 | + /** |
| 182 | + * |
| 183 | + * @example |
| 184 | + * |
| 185 | + * ```ts |
| 186 | + * // Single entry |
| 187 | + * entries: "src/index.ts" // -> outDir/index.js |
| 188 | + * |
| 189 | + * // Multiple entries |
| 190 | + * entries: [ |
| 191 | + * "src/index.ts", // -> outDir/index.js |
| 192 | + * "src/another-entry.ts" // -> outDir/another-entry.js |
| 193 | + * ] |
| 194 | + * |
| 195 | + * // Named multiple entries |
| 196 | + * entries: { |
| 197 | + * bootstrap: "src/bootstrap.ts", // -> outDir/bootstrap.js |
| 198 | + * content: "src/content.ts", // -> outDir/content.js |
| 199 | + * 'components/Foo': 'src/components/Foo.js', // -> outDir/components/Foo.js |
| 200 | + * } |
| 201 | + * ``` |
| 202 | + * |
| 203 | + * The outDir is based on {@linkcode Config.dist | dist/build/addon }. |
| 204 | + * |
| 205 | + * @see https://rolldown.rs/reference/InputOptions.input |
| 206 | + */ |
| 207 | + input: InputOptions["input"]; |
| 208 | + |
| 209 | + /** |
| 210 | + * Replace global variables or [property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) with the provided values. |
| 211 | + * |
| 212 | + * See Oxc's [`define` option](https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement.html#define) for more details. |
| 213 | + * |
| 214 | + */ |
| 215 | + define?: TransformOptions["define"]; |
| 216 | + |
| 217 | + /** |
| 218 | + * Minify the output using rolldown. |
| 219 | + * |
| 220 | + * Defaults to `false` if not provided. |
| 221 | + */ |
| 222 | + minify?: boolean | "dce-only" | MinifyOptions; |
| 223 | + |
| 224 | + /** |
| 225 | + * Options passed to rolldown. |
| 226 | + * |
| 227 | + * See [rolldown config options](https://rolldown.rs/reference/config-options) for more details. |
| 228 | + */ |
| 229 | + rolldown?: Omit<InputOptions, "input"> & { plugins?: RolldownPluginOption[] }; |
| 230 | +} |
| 231 | + |
177 | 232 | export interface BuildConfig { |
178 | 233 | /** |
179 | 234 | * The static assets. |
@@ -294,22 +349,42 @@ export interface BuildConfig { |
294 | 349 | dts: false | string; |
295 | 350 | }; |
296 | 351 | /** |
297 | | - * Configurations of esbuild. |
| 352 | + * Configurations for code bundler (rolldown). |
| 353 | + * |
| 354 | + * Paths should be relative to the root directory of the project. |
| 355 | + * And if `output.file` and `output.dir` not start with `dist`, |
| 356 | + * `dist/` will be automatically added as a prefix. |
| 357 | + * |
| 358 | + * 代码捆绑器(rolldown)的配置。 |
| 359 | + * |
| 360 | + * 路径应相对于项目根目录。 |
| 361 | + * 其中"output.file"和"output.dir"若不以 `dist` 开头, |
| 362 | + * 则会自动添加 `dist/` 前缀。 |
| 363 | + * |
| 364 | + * @default [] |
| 365 | + * |
| 366 | + * @deprecated Use `build.bundle` instead. |
| 367 | + * |
| 368 | + */ |
| 369 | + esbuildOptions: esbuildConfig[]; |
| 370 | + /** |
| 371 | + * Configurations for code bundler (rolldown). |
298 | 372 | * |
299 | 373 | * Paths should be relative to the root directory of the project. |
300 | | - * And if `outfile` and `outdir` not start with `dist`, |
| 374 | + * And if `output.file` and `output.dir` not start with `dist`, |
301 | 375 | * `dist/` will be automatically added as a prefix. |
302 | 376 | * |
303 | | - * esbuild 配置。 |
| 377 | + * 代码捆绑器(rolldown)的配置。 |
304 | 378 | * |
305 | 379 | * 路径应相对于项目根目录。 |
306 | | - * 其中“outfile”和“outdir”若不以 `dist` 开头, |
| 380 | + * 其中"output.file"和"output.dir"若不以 `dist` 开头, |
307 | 381 | * 则会自动添加 `dist/` 前缀。 |
308 | 382 | * |
309 | 383 | * @default [] |
310 | 384 | * |
311 | 385 | */ |
312 | | - esbuildOptions: BuildOptions[]; |
| 386 | + bundle: Arrayable<BundleItem>; |
| 387 | + |
313 | 388 | /** |
314 | 389 | * Make manifest.json. |
315 | 390 | * |
|
0 commit comments