Skip to content

Commit 371156e

Browse files
authored
Remove line breaks to simplify syncs
1 parent bd0c9d8 commit 371156e

File tree

1 file changed

+14
-46
lines changed

1 file changed

+14
-46
lines changed

content/docs/code-splitting.md

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ permalink: docs/code-splitting.html
66

77
## Bundling {#bundling}
88

9-
Most React apps will have their files "bundled" using tools like
10-
[Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/) or
11-
[Browserify](http://browserify.org/).
12-
Bundling is the process of following imported files and merging them into a
13-
single file: a "bundle". This bundle can then be included on a webpage to load
14-
an entire app at once.
9+
Most React apps will have their files "bundled" using tools like [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/) or [Browserify](http://browserify.org/). Bundling is the process of following imported files and merging them into a single file: a "bundle". This bundle can then be included on a webpage to load an entire app at once.
1510

1611
#### Example {#example}
1712

@@ -45,38 +40,22 @@ console.log(add(16, 26)); // 42
4540
>
4641
> Your bundles will end up looking a lot different than this.
4742
48-
If you're using [Create React App](https://create-react-app.dev/), [Next.js](https://nextjs.org/), [Gatsby](https://www.gatsbyjs.org/), or a similar tool, you will have a Webpack setup out of the box to bundle your
49-
app.
43+
If you're using [Create React App](https://create-react-app.dev/), [Next.js](https://nextjs.org/), [Gatsby](https://www.gatsbyjs.org/), or a similar tool, you will have a Webpack setup out of the box to bundle your app.
5044

51-
If you aren't, you'll need to setup bundling yourself. For example, see the
52-
[Installation](https://webpack.js.org/guides/installation/) and
53-
[Getting Started](https://webpack.js.org/guides/getting-started/) guides on the
54-
Webpack docs.
45+
If you aren't, you'll need to setup bundling yourself. For example, see the [Installation](https://webpack.js.org/guides/installation/) and [Getting Started](https://webpack.js.org/guides/getting-started/) guides on the Webpack docs.
5546

5647
## Code Splitting {#code-splitting}
5748

58-
Bundling is great, but as your app grows, your bundle will grow too. Especially
59-
if you are including large third-party libraries. You need to keep an eye on
60-
the code you are including in your bundle so that you don't accidentally make
61-
it so large that your app takes a long time to load.
49+
Bundling is great, but as your app grows, your bundle will grow too. Especially if you are including large third-party libraries. You need to keep an eye on the code you are including in your bundle so that you don't accidentally make it so large that your app takes a long time to load.
6250

63-
To avoid winding up with a large bundle, it's good to get ahead of the problem
64-
and start "splitting" your bundle.
65-
Code-Splitting is a feature
66-
supported by bundlers like [Webpack](https://webpack.js.org/guides/code-splitting/), [Rollup](https://rollupjs.org/guide/en/#code-splitting) and Browserify (via
67-
[factor-bundle](https://github.com/browserify/factor-bundle)) which can create
68-
multiple bundles that can be dynamically loaded at runtime.
51+
To avoid winding up with a large bundle, it's good to get ahead of the problem and start "splitting" your bundle. Code-Splitting is a feature
52+
supported by bundlers like [Webpack](https://webpack.js.org/guides/code-splitting/), [Rollup](https://rollupjs.org/guide/en/#code-splitting) and Browserify (via [factor-bundle](https://github.com/browserify/factor-bundle)) which can create multiple bundles that can be dynamically loaded at runtime.
6953

70-
Code-splitting your app can help you "lazy-load" just the things that are
71-
currently needed by the user, which can dramatically improve the performance of
72-
your app. While you haven't reduced the overall amount of code in your app,
73-
you've avoided loading code that the user may never need, and reduced the amount
74-
of code needed during the initial load.
54+
Code-splitting your app can help you "lazy-load" just the things that are currently needed by the user, which can dramatically improve the performance of your app. While you haven't reduced the overall amount of code in your app, you've avoided loading code that the user may never need, and reduced the amount of code needed during the initial load.
7555

7656
## `import()` {#import}
7757

78-
The best way to introduce code-splitting into your app is through the dynamic
79-
`import()` syntax.
58+
The best way to introduce code-splitting into your app is through the dynamic `import()` syntax.
8059

8160
**Before:**
8261

@@ -94,16 +73,11 @@ import("./math").then(math => {
9473
});
9574
```
9675

97-
When Webpack comes across this syntax, it automatically starts code-splitting
98-
your app. If you're using Create React App, this is already configured for you
99-
and you can [start using it](https://create-react-app.dev/docs/code-splitting/) immediately. It's also supported
100-
out of the box in [Next.js](https://nextjs.org/docs/advanced-features/dynamic-import).
76+
When Webpack comes across this syntax, it automatically starts code-splitting your app. If you're using Create React App, this is already configured for you and you can [start using it](https://create-react-app.dev/docs/code-splitting/) immediately. It's also supported out of the box in [Next.js](https://nextjs.org/docs/advanced-features/dynamic-import).
10177

102-
If you're setting up Webpack yourself, you'll probably want to read Webpack's
103-
[guide on code splitting](https://webpack.js.org/guides/code-splitting/). Your Webpack config should look vaguely [like this](https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269).
78+
If you're setting up Webpack yourself, you'll probably want to read Webpack's [guide on code splitting](https://webpack.js.org/guides/code-splitting/). Your Webpack config should look vaguely [like this](https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269).
10479

105-
When using [Babel](https://babeljs.io/), you'll need to make sure that Babel can
106-
parse the dynamic import syntax but is not transforming it. For that you will need [@babel/plugin-syntax-dynamic-import](https://classic.yarnpkg.com/en/package/@babel/plugin-syntax-dynamic-import).
80+
When using [Babel](https://babeljs.io/), you'll need to make sure that Babel can parse the dynamic import syntax but is not transforming it. For that you will need [@babel/plugin-syntax-dynamic-import](https://classic.yarnpkg.com/en/package/@babel/plugin-syntax-dynamic-import).
10781

10882
## `React.lazy` {#reactlazy}
10983

@@ -196,17 +170,11 @@ const MyComponent = () => (
196170

197171
## Route-based code splitting {#route-based-code-splitting}
198172

199-
Deciding where in your app to introduce code splitting can be a bit tricky. You
200-
want to make sure you choose places that will split bundles evenly, but won't
201-
disrupt the user experience.
173+
Deciding where in your app to introduce code splitting can be a bit tricky. You want to make sure you choose places that will split bundles evenly, but won't disrupt the user experience.
202174

203-
A good place to start is with routes. Most people on the web are used to
204-
page transitions taking some amount of time to load. You also tend to be
205-
re-rendering the entire page at once so your users are unlikely to be
206-
interacting with other elements on the page at the same time.
175+
A good place to start is with routes. Most people on the web are used to page transitions taking some amount of time to load. You also tend to be re-rendering the entire page at once so your users are unlikely to be interacting with other elements on the page at the same time.
207176

208-
Here's an example of how to setup route-based code splitting into your app using
209-
libraries like [React Router](https://reacttraining.com/react-router/) with `React.lazy`.
177+
Here's an example of how to setup route-based code splitting into your app using libraries like [React Router](https://reacttraining.com/react-router/) with `React.lazy`.
210178

211179
```js
212180
import React, { Suspense, lazy } from 'react';

0 commit comments

Comments
 (0)