vite.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env node
  2. if (!__dirname.includes('node_modules')) {
  3. try {
  4. // only available as dev dependency
  5. require('source-map-support').install()
  6. } catch (e) {}
  7. }
  8. global.__vite_start_time = Date.now()
  9. // check debug mode first before requiring the CLI.
  10. const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg))
  11. const filterIndex = process.argv.findIndex((arg) =>
  12. /^(?:-f|--filter)$/.test(arg)
  13. )
  14. const profileIndex = process.argv.indexOf('--profile')
  15. if (debugIndex > 0) {
  16. let value = process.argv[debugIndex + 1]
  17. if (!value || value.startsWith('-')) {
  18. value = 'vite:*'
  19. } else {
  20. // support debugging multiple flags with comma-separated list
  21. value = value
  22. .split(',')
  23. .map((v) => `vite:${v}`)
  24. .join(',')
  25. }
  26. process.env.DEBUG = value
  27. if (filterIndex > 0) {
  28. const filter = process.argv[filterIndex + 1]
  29. if (filter && !filter.startsWith('-')) {
  30. process.env.VITE_DEBUG_FILTER = filter
  31. }
  32. }
  33. }
  34. function start() {
  35. require('../dist/node/cli')
  36. }
  37. if (profileIndex > 0) {
  38. process.argv.splice(profileIndex, 1)
  39. const next = process.argv[profileIndex]
  40. if (next && !next.startsWith('-')) {
  41. process.argv.splice(profileIndex, 1)
  42. }
  43. const inspector = require('inspector')
  44. const session = (global.__vite_profile_session = new inspector.Session())
  45. session.connect()
  46. session.post('Profiler.enable', () => {
  47. session.post('Profiler.start', start)
  48. })
  49. } else {
  50. start()
  51. }