trim-vapor-exports.js 967 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // @ts-check
  2. /**
  3. * runtime-core exports a number of internal helpers that are only used by
  4. * runtime-vapor, which should be only preserved in vapor / esm-bundler builds.
  5. * This plugin should be included as the first plugin for all other formats
  6. * other than vapor / esm-bundler.
  7. *
  8. * @param {string} format
  9. * @param {string} pkgName
  10. * @returns {import('rolldown').Plugin[]}
  11. */
  12. export function trimVaporExportsPlugin(format, pkgName) {
  13. if (
  14. format.includes('vapor') ||
  15. format.startsWith('esm-bundler') ||
  16. pkgName === '@vue/runtime-vapor'
  17. ) {
  18. return []
  19. } else {
  20. return [
  21. {
  22. name: 'trim-vapor-exports',
  23. transform: {
  24. filter: {
  25. id: {
  26. include: /runtime-(core|dom)\/src\/index\.ts$/,
  27. },
  28. },
  29. handler(code) {
  30. const index = code.lastIndexOf('// VAPOR ---')
  31. return code.slice(0, index)
  32. },
  33. },
  34. },
  35. ]
  36. }
  37. }