trim-vapor-exports.js 871 B

123456789101112131415161718192021222324252627282930313233
  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('rollup').Plugin[]}
  11. */
  12. export function trimVaporExportsPlugin(format, pkgName) {
  13. if (
  14. format === '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 (id.endsWith('runtime-core/src/index.ts')) {
  25. const index = code.lastIndexOf('// VAPOR ---')
  26. return code.slice(0, index)
  27. }
  28. },
  29. },
  30. ]
  31. }
  32. }