Skip to content

Commit d8e7831

Browse files
Dynamic import example added
1 parent a297f82 commit d8e7831

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

public/index.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
2+
23
<head>
3-
<link rel="icon" href="./favicon.ico"/>
4+
<link rel="icon" href="./favicon.ico" />
45
<title>React suspense + webpack code splitting</title>
56
<style>
67
html,
@@ -49,6 +50,17 @@
4950
<body>
5051
<main id="app"></main>
5152
<script src="./build/bundle.js"></script>
53+
54+
<!-- Dynamic import example -->
55+
<script type="module">
56+
import('./index.js')
57+
.then(module => {
58+
console.log(module.default());
59+
})
60+
.catch(error => {
61+
console.log(error);
62+
})
63+
</script>
5264
</body>
5365

54-
</html>
66+
</html>

public/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Dynamically loaded module
2+
3+
const module = () => {
4+
return 'I am dynamically loaded!';
5+
};
6+
7+
export default module;

src/components/Router.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { BrowserRouter, Route, Link, Redirect } from "react-router-dom";
3-
43
import Home from './Home';
54
import Profile from './Profile';
65
import Messages from './Messages';

0 commit comments

Comments
 (0)