trim-vapor-exports.js 958 B

123456789101112131415161718192021222324252627282930313233343536
  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(code, id) {
  24. if (
  25. id.endsWith('runtime-core/src/index.ts') ||
  26. id.endsWith('runtime-dom/src/index.ts')
  27. ) {
  28. const index = code.lastIndexOf('// VAPOR ---')
  29. return code.slice(0, index)
  30. }
  31. },
  32. },
  33. ]
  34. }
  35. }