-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
main.js
65 lines (52 loc) · 1.45 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import './style.css'
import viteSvgPath from './vite.svg'
import MyWorker from './worker?worker'
async function run() {
const { fn } = await import('./async.js')
fn()
}
run()
let isLegacy
// make sure that branching works despite esbuild's constant folding (#1999)
if (import.meta.env.LEGACY) {
if (import.meta.env.LEGACY === true) isLegacy = true
} else {
if (import.meta.env.LEGACY === false) isLegacy = false
}
text('#env', `is legacy: ${isLegacy}`)
// Iterators
text('#iterators', [...new Set(['hello'])].join(''))
// structuredClone is supported core.js v3.20.0+
text(
'#features-after-corejs-3',
JSON.stringify(structuredClone({ foo: 'foo' }))
)
// babel-helpers
// Using `String.raw` to inject `@babel/plugin-transform-template-literals`
// helpers.
text(
'#babel-helpers',
String.raw`exposed babel helpers: ${window._templateObject != null}`
)
// dynamic chunk names
import('./immutable-chunk.js')
.then(({ fn }) => fn())
.then((assets) => {
text('#assets', assets.join('\n'))
})
// dynamic css
document
.querySelector('#dynamic-css-button')
.addEventListener('click', async () => {
await import('./dynamic.css')
text('#dynamic-css', 'dynamic import css')
})
text('#asset-path', viteSvgPath)
function text(el, text) {
document.querySelector(el).textContent = text
}
const worker = new MyWorker()
worker.postMessage('ping')
worker.addEventListener('message', (ev) => {
text('.worker-message', JSON.stringify(ev.data))
})