1
1
import type { ErrorPayload } from 'vite'
2
2
3
- const template = `
3
+ const template = ( errors : string [ ] ) => `
4
4
<style>
5
5
:host {
6
6
position: fixed;
7
- z-index: 99999;
7
+ z-index: 9999;
8
8
top: 0;
9
9
left: 0;
10
10
width: 100%;
@@ -26,21 +26,21 @@ const template = `
26
26
line-height: 1.5;
27
27
width: 800px;
28
28
color: #d8d8d8;
29
- margin: 30px auto;
30
- padding: 25px 40px ;
29
+ margin: 40px auto;
30
+ padding: 8px 16px ;
31
31
position: relative;
32
- background: #181818 ;
32
+ background: #0D1117 ;
33
33
border-radius: 6px 6px 8px 8px;
34
34
box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
35
- overflow: hidden;
36
- border-top: 8px solid var(--red);
35
+ overflow: scroll;
37
36
direction: ltr;
38
37
text-align: left;
38
+ max-height: 80vh;
39
39
}
40
40
41
41
pre {
42
42
font-family: var(--monospace);
43
- font-size: 16px ;
43
+ font-size: 14px ;
44
44
margin-top: 0;
45
45
margin-bottom: 1em;
46
46
overflow-x: scroll;
@@ -51,6 +51,15 @@ pre::-webkit-scrollbar {
51
51
display: none;
52
52
}
53
53
54
+ .message-item {
55
+ border-top: 1px dotted #666;
56
+ padding: 12px 0 0 0;
57
+ }
58
+
59
+ .message-item:first-child {
60
+ border-top: none;
61
+ }
62
+
54
63
.message {
55
64
line-height: 1.3;
56
65
font-weight: 600;
@@ -100,10 +109,7 @@ code {
100
109
}
101
110
</style>
102
111
<div class="window">
103
- <pre class="message"><span class="plugin"></span><span class="message-body"></span></pre>
104
- <pre class="file"></pre>
105
- <pre class="frame"></pre>
106
- <pre class="stack"></pre>
112
+ ${ errors . join ( '\n' ) }
107
113
<div class="tip">
108
114
Click outside or fix the code to dismiss.<br>
109
115
You can also disable this overlay by setting
@@ -112,36 +118,50 @@ code {
112
118
</div>
113
119
`
114
120
121
+ const errorTemplate = `
122
+ <div class="message-item">
123
+ <pre class="message"><span class="plugin"></span><span class="message-body"></span></pre>
124
+ <pre class="file"></pre>
125
+ <pre class="frame"></pre>
126
+ <pre class="stack"></pre>
127
+
128
+ </div>
129
+ `
130
+
115
131
const fileRE = / (?: [ a - z A - Z ] : \\ | \/ ) .* ?: \d + : \d + / g
116
132
const codeframeRE = / ^ (?: > ? \s + \d + \s + \| .* | \s + \| \s * \^ .* ) \r ? \n / gm
117
133
118
134
export class ErrorOverlay extends HTMLElement {
119
135
public root : ShadowRoot
120
136
121
- public constructor ( err : ErrorPayload [ 'err' ] ) {
137
+ public constructor ( errs : ErrorPayload [ 'err' ] [ ] ) {
122
138
super ( )
123
139
this . root = this . attachShadow ( { mode : 'open' } )
124
- this . root . innerHTML = template
140
+ this . root . innerHTML = template ( new Array ( errs . length ) . fill ( errorTemplate ) )
125
141
126
- codeframeRE . lastIndex = 0
127
- const hasFrame = err . frame && codeframeRE . test ( err . frame )
128
- const message = hasFrame ? err . message . replace ( codeframeRE , '' ) : err . message
129
- if ( err . plugin ) {
130
- this . text ( '.plugin' , `[plugin:${ err . plugin } ] ` )
131
- }
132
- this . text ( '.message-body' , message . trim ( ) )
142
+ errs . forEach ( ( err , index ) => {
143
+ codeframeRE . lastIndex = 0
144
+ const hasFrame = err . frame && codeframeRE . test ( err . frame )
145
+ const message = hasFrame ? err . message . replace ( codeframeRE , '' ) : err . message
146
+ const selectorPrefix = `.message-item:nth-child(${ index + 1 } ) `
133
147
134
- const [ file ] = ( err . loc ?. file || err . id || 'unknown file' ) . split ( `?` )
135
- if ( err . loc ) {
136
- this . text ( '.file' , `${ file } :${ err . loc . line } :${ err . loc . column } ` , true )
137
- } else if ( err . id ) {
138
- this . text ( '.file' , file )
139
- }
148
+ if ( err . plugin ) {
149
+ this . text ( selectorPrefix + '.plugin' , `[plugin:${ err . plugin } ] ` )
150
+ }
151
+ this . text ( selectorPrefix + '.message-body' , message . trim ( ) )
140
152
141
- if ( hasFrame ) {
142
- this . text ( '.frame' , err . frame ! . trim ( ) )
143
- }
144
- this . text ( '.stack' , err . stack , true )
153
+ const [ file ] = ( err . loc ?. file || err . id || 'unknown file' ) . split ( `?` )
154
+ if ( err . loc ) {
155
+ this . text ( selectorPrefix + '.file' , `${ file } :${ err . loc . line } :${ err . loc . column } ` , true )
156
+ } else if ( err . id ) {
157
+ this . text ( selectorPrefix + '.file' , file )
158
+ }
159
+
160
+ if ( hasFrame ) {
161
+ this . text ( selectorPrefix + '.frame' , err . frame ! . trim ( ) )
162
+ }
163
+ this . text ( selectorPrefix + '.stack' , err . stack , true )
164
+ } )
145
165
146
166
this . root . querySelector ( '.window' ) ! . addEventListener ( 'click' , ( e ) => {
147
167
e . stopPropagation ( )
0 commit comments