You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-router-dom/docs/guides/code-splitting.md
+13-45Lines changed: 13 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,8 @@
1
1
# Code Splitting
2
2
3
-
One great feature of the web is that we don't have to make our visitors
4
-
download the entire app before they can use it. You can think of code splitting
5
-
as incrementally downloading the app. To accomplish this we'll use [webpack],
6
-
[`babel-plugin-syntax-dynamic-import`], and [`react-loadable`].
3
+
One great feature of the web is that we don't have to make our visitors download the entire app before they can use it. You can think of code splitting as incrementally downloading the app. To accomplish this we'll use [webpack], [`babel-plugin-syntax-dynamic-import`], and [`react-loadable`].
7
4
8
-
[webpack] has built-in support for [dynamic imports][import]; however, if you
9
-
are using [Babel] (e.g., to compile JSX to JavaScript) then you will need to
10
-
use the [`babel-plugin-syntax-dynamic-import`] plugin. This is a syntax-only
11
-
plugin, meaning Babel won't do any additional transformations. The plugin
12
-
simply allows Babel to parse dynamic imports so webpack can bundle them as a
13
-
code split. Your `.babelrc` should look something like this:
5
+
[webpack] has built-in support for [dynamic imports][import]; however, if you are using [Babel] (e.g., to compile JSX to JavaScript) then you will need to use the [`babel-plugin-syntax-dynamic-import`] plugin. This is a syntax-only plugin, meaning Babel won't do any additional transformations. The plugin simply allows Babel to parse dynamic imports so webpack can bundle them as a code split. Your `.babelrc` should look something like this:
14
6
15
7
```json
16
8
{
@@ -23,53 +15,29 @@ code split. Your `.babelrc` should look something like this:
23
15
}
24
16
```
25
17
26
-
[`react-loadable`] is a higher-order component for loading components with
27
-
dynamic imports. It handles all sorts of edge cases automatically and makes
28
-
code splitting simple! Here's an example of how to use [`react-loadable`]:
18
+
[`react-loadable`] is a higher-order component for loading components with dynamic imports. It handles all sorts of edge cases automatically and makes code splitting simple! Here's an example of how to use [`react-loadable`]:
That's all there is to it! Simply use `LoadableComponent` (or whatever you
62
-
named your component) and it will automatically be loaded and rendered when you
63
-
use it in your application. The `loader` option is a function which actually
64
-
loads the component, and `loading` is a placeholder component to show while the
65
-
real component is loading.
36
+
That's all there is to it! Simply use `LoadableDashboard` (or whatever you named your component) and it will automatically be loaded and rendered when you use it in your application. The `loader` option is a function which actually loads the component, and `loading` is a placeholder component to show while the real component is loading.
66
37
67
38
## Code Splitting and Server-Side Rendering
68
39
69
-
[`react-loadable`] includes [a guide for server-side rendering][ssr]. All you
70
-
should need to do is include [`babel-plugin-import-inspector`] in your
71
-
`.babelrc` and server-side rendering should just work™. Here is an example
72
-
`.babelrc` file:
40
+
[`react-loadable`] includes [a guide for server-side rendering][ssr]. All you should need to do is include [`babel-plugin-import-inspector`] in your `.babelrc` and server-side rendering should just work™. Here is an example `.babelrc` file:
0 commit comments