Skip to content

Commit 03393c5

Browse files
committed
Two demos
1 parent 8692be6 commit 03393c5

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed
File renamed without changes.

demo/react-unpkg.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Test</title>
6+
</head>
7+
<body>
8+
<h2>Demo inside a plain HTML page</h2>
9+
10+
<div id="root"></div>
11+
<script type="module">
12+
import { importWithMap } from 'https://unpkg.com/[email protected]';
13+
14+
const importMap = {
15+
imports: {
16+
"react": "https://esm.sh/[email protected]?dev",
17+
"react-dom": "https://esm.sh/[email protected]?dev",
18+
"react-dom/client": "https://esm.sh/[email protected]/client?dev",
19+
"prop-types": "https://esm.sh/[email protected]?dev",
20+
"react-feather": "https://unpkg.com/[email protected]/dist/index.js"
21+
},
22+
};
23+
24+
const React = await importWithMap("react", importMap);
25+
const { createRoot } = await importWithMap("react-dom/client", importMap);
26+
27+
// react-feather is a React icon library
28+
// which contains bare import specifiers for "react" and "prop-types"
29+
const { Smile } = await importWithMap('react-feather', importMap);
30+
31+
function MyApp(props) {
32+
return React.createElement(React.Suspense,
33+
{ fallback: React.createElement('div', {}, 'Loading...') },
34+
React.createElement(Smile),
35+
);
36+
}
37+
38+
const domContainer = document.getElementById('root');
39+
const root = createRoot(domContainer);
40+
root.render(React.createElement(MyApp));
41+
</script>
42+
</body>
43+
</html>

package-lock.json

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"tachometer": "^0.5.10",
4444
"terser": "^5.10.0",
4545
"cypress": "^10.10.0",
46-
"http-server": "^14.0.0"
46+
"http-server": "^14.0.0",
47+
"@rollup/plugin-terser": "^0.4.1"
4748
}
4849
}

rollup.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import replace from '@rollup/plugin-replace';
4+
import terser from '@rollup/plugin-terser';
45

56
const version = JSON.parse(fs.readFileSync('package.json')).version;
67

@@ -30,6 +31,9 @@ function config (isWasm, isDebug) {
3031
'self.ESMS_DEBUG': isDebug.toString(),
3132
preventAssignment: true
3233
}),
34+
...(!isWasm && !isDebug ? [
35+
terser()
36+
] : []),
3337
]
3438
};
3539
}

0 commit comments

Comments
 (0)