index.mjs 1.5 KB

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