1 | #!/usr/bin/env node
|
2 | const { performance } = require('perf_hooks')
|
3 |
|
4 | if (!__dirname.includes('node_modules')) {
|
5 | try {
|
6 |
|
7 | require('source-map-support').install()
|
8 | } catch (e) {}
|
9 | }
|
10 |
|
11 | global.__vite_start_time = performance.now()
|
12 |
|
13 |
|
14 | const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg))
|
15 | const filterIndex = process.argv.findIndex((arg) =>
|
16 | /^(?:-f|--filter)$/.test(arg)
|
17 | )
|
18 | const profileIndex = process.argv.indexOf('--profile')
|
19 |
|
20 | if (debugIndex > 0) {
|
21 | let value = process.argv[debugIndex + 1]
|
22 | if (!value || value.startsWith('-')) {
|
23 | value = 'vite:*'
|
24 | } else {
|
25 |
|
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 |
|
41 | function start() {
|
42 | require('../dist/node/cli')
|
43 | }
|
44 |
|
45 | if (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 | }
|