UNPKG

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