Skip to content

Commit 060dd91

Browse files
committed
Add "minimizing bundle size" guide
1 parent 8d516be commit 060dd91

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

Diff for: docs/README.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
## Table of Contents
22

3-
* [Introduction](/docs/Introduction.md)
4-
* [Basics](/docs/guides/basics/README.md)
5-
* [Route Configuration](/docs/guides/basics/RouteConfiguration.md)
6-
* [Route Matching](/docs/guides/basics/RouteMatching.md)
7-
* [Histories](/docs/guides/basics/Histories.md)
8-
* [Index Routes and Links](/docs/guides/basics/IndexRoutes.md)
9-
* [Advanced Usage](/docs/guides/advanced/README.md)
10-
* [Dynamic Routing](/docs/guides/advanced/DynamicRouting.md)
11-
* [Confirming Navigation](/docs/guides/advanced/ConfirmingNavigation.md)
12-
* [Server Rendering](/docs/guides/advanced/ServerRendering.md)
13-
* [Component Lifecycle](/docs/guides/advanced/ComponentLifecycle.md)
14-
* [Navigating Outside of Components](/docs/guides/advanced/NavigatingOutsideOfComponents.md)
3+
* [Introduction](Introduction.md)
4+
* [Basics](guides/basics/README.md)
5+
* [Route Configuration](guides/basics/RouteConfiguration.md)
6+
* [Route Matching](guides/basics/RouteMatching.md)
7+
* [Histories](guides/basics/Histories.md)
8+
* [Index Routes and Links](guides/basics/IndexRoutes.md)
9+
* [Advanced Usage](guides/advanced/README.md)
10+
* [Dynamic Routing](guides/advanced/DynamicRouting.md)
11+
* [Confirming Navigation](guides/advanced/ConfirmingNavigation.md)
12+
* [Server Rendering](guides/advanced/ServerRendering.md)
13+
* [Component Lifecycle](guides/advanced/ComponentLifecycle.md)
14+
* [Navigating Outside of Components](guides/advanced/NavigatingOutsideOfComponents.md)
15+
* [Minimizing Bundle Size](guides/advanced/MinimizingBundleSize.md)
1516
* [Change Log](/CHANGES.md)
1617
* [Upgrading to v1.0.0](../upgrade-guides/v1.0.0.md)
1718
* [Upgrading to v2.0.0](../upgrade-guides/v2.0.0.md)
18-
* [Troubleshooting](/docs/Troubleshooting.md)
19-
* [API](/docs/API.md)
20-
* [Glossary](/docs/Glossary.md)
19+
* [Troubleshooting](Troubleshooting.md)
20+
* [API](API.md)
21+
* [Glossary](Glossary.md)

Diff for: docs/guides/advanced/MinimizingBundleSize.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Minimizing Bundle Size
2+
3+
For convenience, React Router exposes its full API on the top-level `react-router` import. However, this causes the entire React Router library and its dependencies to be included in client bundles that include code that makes any imports from the top-level CommonJS bundle.
4+
5+
There are two options for minimizing client bundle size by excluding unused modules.
6+
7+
8+
## Import from `react-router/lib`
9+
10+
Bindings exported from `react-router` are also available in `react-router/lib`. When using CommonJS models, you can import directly from `react-router/lib` to avoid pulling in unused modules.
11+
12+
Assuming you are transpiling ES2015 modules into CommonJS modules, instead of
13+
14+
```js
15+
import { Link, Route, Router } from 'react-router'
16+
```
17+
18+
use
19+
20+
```js
21+
import Link from 'react-router/lib/Link'
22+
import Route from 'react-router/lib/Route'
23+
import Router from 'react-router/lib/Router'
24+
```
25+
26+
The public API available in this manner is defined as the set of imports available from the top-level `react-router` module. Anything not available through the top-level `react-router` module is a private API, and is subject to change without notice.
27+
28+
29+
## Use a Bundler with ES2015 Module Support
30+
31+
React Router offers a ES2015 module build under `es6/` and defines a `jsnext:main` entry point. If you are using a bundler that supports ES2015 modules and tree-shaking such as webpack 2 or Rollup, you can directly import from `react-router`, as long as you are correctly resolving to the ES2015 module build.

Diff for: docs/guides/advanced/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
* [Server Rendering](ServerRendering.md)
66
* [Component Lifecycle](ComponentLifecycle.md)
77
* [Navigating Outside of Components](NavigatingOutsideOfComponents.md)
8+
* [Minimizing Bundle Size](MinimizingBundleSize.md)

Diff for: modules/createMemoryHistory.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ export default function createMemoryHistory(options) {
1111
history.__v2_compatible__ = true
1212
return history
1313
}
14-

0 commit comments

Comments
 (0)