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