版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

99 строки
2.2 KiB

  1. import {
  2. getPluginList
  3. } from "./chunk-CPRJCEZG.mjs";
  4. // src/index.ts
  5. import { toArray } from "@antfu/utils";
  6. // src/vite.ts
  7. var getVitePlugin = (factory) => {
  8. return (userOptions) => {
  9. const { plugins } = factory(userOptions, { framework: "vite" });
  10. return resolvePlugins(plugins, "vite");
  11. };
  12. };
  13. // src/esbuild.ts
  14. var getEsbuildPlugin = (factory) => {
  15. return (userOptions) => {
  16. const { name, plugins } = factory(userOptions, { framework: "esbuild" });
  17. return {
  18. name,
  19. setup(build) {
  20. for (const plugin of resolvePlugins(plugins, "esbuild")) {
  21. plugin.setup(build);
  22. }
  23. }
  24. };
  25. };
  26. };
  27. // src/webpack.ts
  28. var getWebpackPlugin = (factory) => {
  29. return (userOptions) => {
  30. const { plugins } = factory(userOptions, { framework: "webpack" });
  31. return (compiler) => {
  32. for (const plugin of resolvePlugins(plugins, "webpack")) {
  33. if (typeof plugin === "object") {
  34. plugin.apply.call(compiler, compiler);
  35. } else {
  36. plugin.call(compiler, compiler);
  37. }
  38. }
  39. };
  40. };
  41. };
  42. // src/index.ts
  43. function flatPlugins(plugins) {
  44. return toArray(plugins).flat(Number.POSITIVE_INFINITY);
  45. }
  46. function resolvePlugins(plugins, type) {
  47. return flatPlugins(plugins).filter(Boolean).map((plugin) => {
  48. if ("instance" in plugin) {
  49. const { instance, options } = plugin;
  50. return instance[type](options);
  51. }
  52. return plugin;
  53. });
  54. }
  55. var createCombinePlugin = (factory) => {
  56. return {
  57. get rollup() {
  58. return getRollupPlugin(factory);
  59. },
  60. get vite() {
  61. return getVitePlugin(factory);
  62. },
  63. get esbuild() {
  64. return getEsbuildPlugin(factory);
  65. },
  66. get webpack() {
  67. return getWebpackPlugin(factory);
  68. },
  69. get raw() {
  70. return factory;
  71. },
  72. get plugins() {
  73. return getPluginList(factory);
  74. }
  75. };
  76. };
  77. // src/rollup.ts
  78. var getRollupPlugin = (factory) => {
  79. return (userOptions) => {
  80. const { plugins } = factory(userOptions, { framework: "rollup" });
  81. return resolvePlugins(plugins, "rollup");
  82. };
  83. };
  84. export {
  85. getRollupPlugin,
  86. getVitePlugin,
  87. getWebpackPlugin,
  88. resolvePlugins,
  89. createCombinePlugin,
  90. getEsbuildPlugin
  91. };