index.mjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { n as __toESM, t as require_binding } from "./shared/binding-C5G6_6ql.mjs";
  2. import { n as onExit, t as watch } from "./shared/watch-B91pWiEX.mjs";
  3. import "./shared/normalize-string-or-regex-C5RWbu3O.mjs";
  4. import { a as BindingMagicString, b as RUNTIME_MODULE_ID, x as VERSION } from "./shared/bindingify-input-options-Cu7pt6SZ.mjs";
  5. import "./shared/rolldown-build-4YnQkA76.mjs";
  6. import "./shared/error-CP8smW_P.mjs";
  7. import "./shared/parse-B3SIKejW.mjs";
  8. import { t as rolldown } from "./shared/rolldown-Lc4TvZmS.mjs";
  9. import { t as defineConfig } from "./shared/define-config-DJOr6Iwt.mjs";
  10. import { isMainThread } from "node:worker_threads";
  11. //#region src/setup.ts
  12. var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
  13. if (isMainThread) {
  14. const subscriberGuard = (0, import_binding.initTraceSubscriber)();
  15. onExit(() => {
  16. subscriberGuard?.close();
  17. });
  18. }
  19. //#endregion
  20. //#region src/api/build.ts
  21. /**
  22. * The API similar to esbuild's `build` function.
  23. *
  24. * @example
  25. * ```js
  26. * import { build } from 'rolldown';
  27. *
  28. * const result = await build({
  29. * input: 'src/main.js',
  30. * output: {
  31. * file: 'bundle.js',
  32. * },
  33. * });
  34. * console.log(result);
  35. * ```
  36. *
  37. * @experimental
  38. * @category Programmatic APIs
  39. */
  40. async function build(options) {
  41. if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
  42. else {
  43. const { output, write = true, ...inputOptions } = options;
  44. const build = await rolldown(inputOptions);
  45. try {
  46. if (write) return await build.write(output);
  47. else return await build.generate(output);
  48. } finally {
  49. await build.close();
  50. }
  51. }
  52. }
  53. //#endregion
  54. export { RUNTIME_MODULE_ID, BindingMagicString as RolldownMagicString, VERSION, build, defineConfig, rolldown, watch };