plugins-index.mjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { a as makeBuiltinPluginCallable, n as BuiltinPlugin } from "./shared/normalize-string-or-regex-CVvpepxa.mjs";
  2. import { t as esmExternalRequirePlugin } from "./shared/constructors-BaEBnHl3.mjs";
  3. //#region src/builtin-plugin/replace-plugin.ts
  4. /**
  5. * Replaces targeted strings in files while bundling.
  6. *
  7. * @example
  8. * **Basic usage**
  9. * ```js
  10. * replacePlugin({
  11. * 'process.env.NODE_ENV': JSON.stringify('production'),
  12. * __buildVersion: 15
  13. * })
  14. * ```
  15. * @example
  16. * **With options**
  17. * ```js
  18. * replacePlugin({
  19. * 'process.env.NODE_ENV': JSON.stringify('production'),
  20. * __buildVersion: 15
  21. * }, {
  22. * preventAssignment: false,
  23. * })
  24. * ```
  25. *
  26. * @see https://rolldown.rs/builtin-plugins/replace
  27. * @category Builtin Plugins
  28. */
  29. function replacePlugin(values = {}, options = {}) {
  30. Object.keys(values).forEach((key) => {
  31. const value = values[key];
  32. if (typeof value !== "string") values[key] = String(value);
  33. });
  34. return makeBuiltinPluginCallable(new BuiltinPlugin("builtin:replace", {
  35. ...options,
  36. values
  37. }));
  38. }
  39. //#endregion
  40. export { esmExternalRequirePlugin, replacePlugin };