index.mjs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { n as __toESM, t as require_binding } from "./shared/binding-B4m_2rFW.mjs";
  2. import { n as onExit, t as watch } from "./shared/watch-DPhTjCBr.mjs";
  3. import { T as VERSION, s as RolldownMagicString } from "./shared/bindingify-input-options-DCTviPFW.mjs";
  4. import { t as rolldown } from "./shared/rolldown-jmAeXo_f.mjs";
  5. import { t as defineConfig } from "./shared/define-config-Demdg3_4.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/constants/index.ts
  17. /**
  18. * Runtime helper module ID
  19. */
  20. const RUNTIME_MODULE_ID = "\0rolldown/runtime.js";
  21. //#endregion
  22. //#region src/api/build.ts
  23. /**
  24. * The API similar to esbuild's `build` function.
  25. *
  26. * @example
  27. * ```js
  28. * import { build } from 'rolldown';
  29. *
  30. * const result = await build({
  31. * input: 'src/main.js',
  32. * output: {
  33. * file: 'bundle.js',
  34. * },
  35. * });
  36. * console.log(result);
  37. * ```
  38. *
  39. * @experimental
  40. * @category Programmatic APIs
  41. */
  42. async function build(options) {
  43. if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
  44. else {
  45. const { output, write = true, ...inputOptions } = options;
  46. const build = await rolldown(inputOptions);
  47. try {
  48. if (write) return await build.write(output);
  49. else return await build.generate(output);
  50. } finally {
  51. await build.close();
  52. }
  53. }
  54. }
  55. //#endregion
  56. export { RUNTIME_MODULE_ID, RolldownMagicString, VERSION, build, defineConfig, rolldown, watch };