/
index.html
64 lines (47 loc) · 1.39 KB
/
index.html
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
<h2>Normal Import</h2>
<pre class="full"></pre>
<pre class="named"></pre>
<h2>Deep Import</h2>
<pre class="deep-full"></pre>
<pre class="deep-named"></pre>
<h2>Dynamic Import</h2>
<pre class="dynamic"></pre>
<pre class="dynamic-named"></pre>
<h2>fetch</h2>
<pre class="fetch"></pre>
<h2>Importing as URL</h2>
<pre class="url"></pre>
<h2>Raw Import</h2>
<pre class="raw"></pre>
<h2>JSON Module</h2>
<pre class="module"></pre>
<h2>Has BOM Tag</h2>
<pre class="bom"></pre>
<script type="module">
import json, { hello } from './test.json'
import deepJson, { name } from 'vue/package.json'
text('.full', JSON.stringify(json))
text('.named', hello)
text('.deep-full', JSON.stringify(deepJson))
text('.deep-named', name)
import('/test.json').then((mod) => {
text('.dynamic', JSON.stringify(mod.default))
text('.dynamic-named', mod.hello)
})
fetch(import.meta.env.DEV ? '/test.json' : '/public.json')
.then((r) => r.json())
.then((data) => {
text('.fetch', JSON.stringify(data))
})
import url from './test.json?url'
text('.url', url)
import raw from './test.json?raw'
text('.raw', raw)
import moduleJSON from 'json-module'
text('.module', JSON.stringify(moduleJSON))
import hasBomJson from './json-bom/has-bom.json'
text('.bom', JSON.stringify(hasBomJson))
function text(sel, text) {
document.querySelector(sel).textContent = text
}
</script>