forked from diy4869/otaku-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.html
80 lines (58 loc) · 1.87 KB
/
test2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style></style>
</head>
<body>
<div id="app"></div>
</body>
<script>
const container = document.getElementById('app')
const module = new Map()
async function require (id, URL) {
function loadScript (URL) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.open('GET', URL)
xhr.send()
xhr.onreadystatechange = function (e) {
if (e.target.readyState === 4 && e.target.status === 200) {
console.log(e)
const code = new Function(
'exports = {}',
`${e.target.responseText}\n\n return exports`
)
const result = code.call(null, {})
resolve(result)
}
}
})
}
try {
if (!module.has(id)) {
const result = await loadScript(URL)
module.set(id, result)
return module.get(id)
}
} catch (err) {
}
}
(async function () {
var React = await require('react', 'https://unpkg.com/react@18/umd/react.development.js')
console.log('react', React)
console.log(window.React)
debugger
var ReactDOM = require('react-dom/client', 'https://unpkg.com/react-dom@18/umd/react-dom.development.js')
function App() {
return React.createElement('div', null, 'hello world')
}
ReactDOM
.createRoot(container)
.render(React.createElement(App, null))
})()
</script>
</html>