Skip to content

Commit b880f20

Browse files
committed
Translate advanced 'code-splitting' page
1 parent b941619 commit b880f20

File tree

1 file changed

+88
-72
lines changed

1 file changed

+88
-72
lines changed

content/docs/code-splitting.md

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
id: code-splitting
3-
title: Code-Splitting
3+
title: Dzielenie kodu
44
permalink: docs/code-splitting.html
55
---
66

7-
## Bundling {#bundling}
7+
## Pakowanie {#bundling}
88

9-
Most React apps will have their files "bundled" using tools like
9+
Większość Reactowych aplikacji będzie "dołączała" swoje pliki przez narzędzia takie jak
1010
[Webpack](https://webpack.js.org/) or [Browserify](http://browserify.org/).
11-
Bundling is the process of following imported files and merging them into a
12-
single file: a "bundle". This bundle can then be included on a webpage to load
13-
an entire app at once.
11+
Pakowanie to proces śledzenia zaimportowanych plików i łączenia je w pojedynczy plik "bundle".
12+
Tak zbudowany pakiet jest gotowy do umieszczenia na stronie aby załadować całą aplikację.
1413

15-
#### Example {#example}
14+
#### Przykład {#example}
1615

1716
**App:**
1817

@@ -40,86 +39,90 @@ function add(a, b) {
4039
console.log(add(16, 26)); // 42
4140
```
4241

43-
> Note:
42+
> Notatka:
4443
>
45-
> Your bundles will end up looking a lot different than this.
44+
> Twoje pakiety prawdopodobnie będą wyglądać znacznie inaczej
4645
47-
If you're using [Create React App](https://github.com/facebookincubator/create-react-app), [Next.js](https://github.com/zeit/next.js/), [Gatsby](https://www.gatsbyjs.org/), or a similar tool, you will have a Webpack setup out of the box to bundle your
48-
app.
46+
Jeśli używasz [Create React App](https://github.com/facebookincubator/create-react-app),
47+
[Next.js](https://github.com/zeit/next.js/), [Gatsby](https://www.gatsbyjs.org/),
48+
lub innego podobnego narzędzia, będziesz miał gotową do pakowania konfigurację Webpacka.
4949

50-
If you aren't, you'll need to setup bundling yourself. For example, see the
51-
[Installation](https://webpack.js.org/guides/installation/) and
52-
[Getting Started](https://webpack.js.org/guides/getting-started/) guides on the
53-
Webpack docs.
50+
Jeśli nie, będziesz potrzebował samodzielnie skonfigurować webpacka.
51+
Dla przykładu zerknij na przewodnik po
52+
[Instalacji](https://webpack.js.org/guides/installation/) oraz
53+
[Podstawowe informacje](https://webpack.js.org/guides/getting-started/) zawarte w dokumentacji
54+
Webpacka.
5455

55-
## Code Splitting {#code-splitting}
56+
## Dzielenie kodu {#code-splitting}
5657

57-
Bundling is great, but as your app grows, your bundle will grow too. Especially
58-
if you are including large third-party libraries. You need to keep an eye on
59-
the code you are including in your bundle so that you don't accidentally make
60-
it so large that your app takes a long time to load.
58+
Pakowanie jest świetne, ale wraz ze wzrostem twojej aplikacji, rośnie również paczka.
59+
Zwłaszcza gdy dołączasz do projektu duże, zewnętrzne biblioteki.
60+
Musisz pilnować, aby twój pakiet nie był zbyt duży, ponieważ wtedy aplikacja
61+
będzie się długo ładowała.
6162

62-
To avoid winding up with a large bundle, it's good to get ahead of the problem
63-
and start "splitting" your bundle.
64-
[Code-Splitting](https://webpack.js.org/guides/code-splitting/) is a feature
65-
supported by bundlers like Webpack and Browserify (via
66-
[factor-bundle](https://github.com/browserify/factor-bundle)) which can create
67-
multiple bundles that can be dynamically loaded at runtime.
63+
Aby uniknąć problemu zbyt dużego pakietu, warto już na początku o tym pomyśleć
64+
i rozpocząć "dzielenie" swojej paczki.
65+
[Dzielenie kodu](https://webpack.js.org/guides/code-splitting/) to funkcja
66+
wspierana przez narzędzia takie jak Webpack oraz Browserify (przez
67+
[factor-bundle](https://github.com/browserify/factor-bundle)) które mogą tworzyć
68+
wiele dynamicznie ładujących się pakietów w czasie wykonania.
6869

69-
Code-splitting your app can help you "lazy-load" just the things that are
70-
currently needed by the user, which can dramatically improve the performance of
71-
your app. While you haven't reduced the overall amount of code in your app,
72-
you've avoided loading code that the user may never need, and reduced the amount
73-
of code needed during the initial load.
70+
Dzielenie kodu ułatwi ci "leniwe ładowanie" tylko aktualnie wymaganych przez
71+
użytkownika zasobów, co może znacznie poprawić wydajność twojej aplikacji.
72+
Mimo, że sumarycznie nie zmniejszasz ilości kodu, unikasz ładowania
73+
w danym momencie zbędnych dla użytkownika funkcji, co przekłada się na mniejszą ilość kodu do pobrania.
7474

7575
## `import()` {#import}
7676

77-
The best way to introduce code-splitting into your app is through the dynamic
78-
`import()` syntax.
77+
Najlepszym sposobem na wprowadzenie podziału kodu do twojej aplikacji jest dynamiczna składnia
78+
`import()`.
7979

80-
**Before:**
80+
**Przed:**
8181

8282
```js
8383
import { add } from './math';
8484

8585
console.log(add(16, 26));
8686
```
8787

88-
**After:**
88+
**Po:**
8989

9090
```js
9191
import("./math").then(math => {
9292
console.log(math.add(16, 26));
9393
});
9494
```
9595

96-
> Note:
96+
> Notatka:
9797
>
98-
> The dynamic `import()` syntax is a ECMAScript (JavaScript)
99-
> [proposal](https://github.com/tc39/proposal-dynamic-import) not currently
100-
> part of the language standard. It is expected to be accepted in the
101-
> near future.
98+
> Dynamiczna składnia `import()` to [propozycja](https://github.com/tc39/proposal-dynamic-import)
99+
> ECMAScript (JavaScript), która aktualnie nie jest częścią standardu językowego. Oczekuje się natomiast,
100+
> że wkrótce zostanie zaakceptowana jako powszechny standard.
102101
103-
When Webpack comes across this syntax, it automatically starts code-splitting
104-
your app. If you're using Create React App, this is already configured for you
105-
and you can [start using it](https://facebook.github.io/create-react-app/docs/code-splitting) immediately. It's also supported
106-
out of the box in [Next.js](https://github.com/zeit/next.js/#dynamic-import).
102+
Gdy Webpack natknie się na taką składnie, automatycznie zacznie dzielić kod w twojej aplikacji.
103+
Jeśli używasz Create React App, posiadasz już gotową konfigurację i możesz natychmiast
104+
[zacząć z niego korzystać](https://facebook.github.io/create-react-app/docs/code-splitting).
105+
Również gotowo obsługuje to [Next.js](https://github.com/zeit/next.js/#dynamic-import).
107106

108-
If you're setting up Webpack yourself, you'll probably want to read Webpack's
109-
[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).
107+
Jeśli konfigurujesz Webpacka samodzielnie, prawdopodobnie chcesz przeczytać
108+
[przewodnik po dzieleniu kodu Webpack](https://webpack.js.org/guides/code-splitting/).
109+
Twoja konfiguracja Webpacka powinna wyglądać podobnie [do tego](https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269).
110110

111-
When using [Babel](https://babeljs.io/), you'll need to make sure that Babel can
112-
parse the dynamic import syntax but is not transforming it. For that you will need [babel-plugin-syntax-dynamic-import](https://yarnpkg.com/en/package/babel-plugin-syntax-dynamic-import).
111+
Kiedy używasz [Babel](https://babeljs.io/), musisz się upewnić, że Babel może analizować dynamiczną
112+
składnie importu, ale jej nie przekształca. Do tego będziesz potrzebować [babel-plugin-syntax-dynamic-import](https://yarnpkg.com/en/package/babel-plugin-syntax-dynamic-import).
113113

114114
## `React.lazy` {#reactlazy}
115115

116-
> Note:
116+
> Notatka:
117117
>
118-
> `React.lazy` and Suspense is not yet available for server-side rendering. If you want to do code-splitting in a server rendered app, we recommend [Loadable Components](https://github.com/smooth-code/loadable-components). It has a nice [guide for bundle splitting with server-side rendering](https://github.com/smooth-code/loadable-components/blob/master/packages/server/README.md).
118+
> `React.lazy` i Suspense nie jest jeszcze dostępne dla renderowania po stronie serwera
119+
> Jeśli chcesz dzielić kod dla aplikacji renderowanej na serwerze zalecamy [Komponenty Ładowalne
120+
> (Loadable Components)](https://github.com/smooth-code/loadable-components).
121+
> Mają przyjemny [przewodnik do dzielenia pakietów przy renderowaniu po stronie serwera](https://github.com/smooth-code/loadable-components/blob/master/packages/server/README.md).
119122
120-
The `React.lazy` function lets you render a dynamic import as a regular component.
123+
Funkcja `React.lazy` pozwala ci dynamicznie renderować importy jako regularne komponenty.
121124

122-
**Before:**
125+
**Przed:**
123126

124127
```js
125128
import OtherComponent from './OtherComponent';
@@ -133,7 +136,7 @@ function MyComponent() {
133136
}
134137
```
135138

136-
**After:**
139+
**Po:**
137140

138141
```js
139142
const OtherComponent = React.lazy(() => import('./OtherComponent'));
@@ -147,13 +150,17 @@ function MyComponent() {
147150
}
148151
```
149152

150-
This will automatically load the bundle containing the `OtherComponent` when this component gets rendered.
153+
To automatycznie załaduje paczke zawierającą `OtherComponent` kiedy komponent będzie renderowany.
151154

152-
`React.lazy` takes a function that must call a dynamic `import()`. This must return a `Promise` which resolves to a module with a `default` export containing a React component.
155+
`React.lazy` przyjmuje funkcję, która dynamicznie woła `import()`.
156+
Musi zwrócić obietnicę (`Promise`) który rozstrzyga moduł z domyślnym (`default`) eksportem zawierający
157+
komponent Reactowy.
153158

154-
### Suspense {#suspense}
159+
### Zawieszenie {#suspense}
155160

156-
If the module containing the `OtherComponent` is not yet loaded by the time `MyComponent` renders, we must show some fallback content while we're waiting for it to load - such as a loading indicator. This is done using the `Suspense` component.
161+
Jeśli moduł zawierający `OtherComponent` nie zostanie jeszcze załadowany na czas renderowania
162+
`MyComponent`, musimy wyświetlić zapasową zawartość, dopóki trwa ładowanie - na przykład
163+
wskaźnik ładowania. Robimy to za pomocą komponentu `Suspense`.
157164

158165
```js
159166
const OtherComponent = React.lazy(() => import('./OtherComponent'));
@@ -169,7 +176,10 @@ function MyComponent() {
169176
}
170177
```
171178

172-
The `fallback` prop accepts any React elements that you want to render while waiting for the component to load. You can place the `Suspense` component anywhere above the lazy component. You can even wrap multiple lazy components with a single `Suspense` component.
179+
Props `fallback` akceptuje wszystkie elementy Reactowe, które chcesz wyświetlić
180+
w trakcie oczekiwania na załadowanie komponentu. Możesz umieścić komponent `Suspense`
181+
w dowolnym miejscu nad "leniwym" komponentem. Możesz nawet zawijać wiele "leniwych komponentów"
182+
za pomocą jednego komponentu `Suspense`.
173183

174184
```js
175185
const OtherComponent = React.lazy(() => import('./OtherComponent'));
@@ -189,9 +199,12 @@ function MyComponent() {
189199
}
190200
```
191201

192-
### Error boundaries {#error-boundaries}
202+
### Granice błędów {#error-boundaries}
193203

194-
If the other module fails to load (for example, due to network failure), it will trigger an error. You can handle these errors to show a nice user experience and manage recovery with [Error Boundaries](/docs/error-boundaries.html). Once you've created your Error Boundary, you can use it anywhere above your lazy components to display an error state when there's a network error.
204+
Jeśli inny moduł się nie doładuje (na przykład z powodu awarii sieci), spowoduje to błąd.
205+
Możesz je obsługiwać aby zapewnić najlepsze doświadczenia użytkownika i zarządzać ratunkiem z pomocą
206+
[Granic Błędów](/docs/error-boundaries.html). Po utworzeniu granic możesz ich użyć w dowolnym
207+
miejscu nad "leniwymi" komponentami, aby wyświetlić stan błędu gdy sieć jest niedostępna.
195208

196209
```js
197210
import MyErrorBoundary from './MyErrorBoundary';
@@ -212,19 +225,19 @@ const MyComponent = () => (
212225
);
213226
```
214227

215-
## Route-based code splitting {#route-based-code-splitting}
228+
## Podział kodu na podstawie szlaku (Route-based) {#route-based-code-splitting}
216229

217-
Deciding where in your app to introduce code splitting can be a bit tricky. You
218-
want to make sure you choose places that will split bundles evenly, but won't
219-
disrupt the user experience.
230+
Decydowanie gdzie w twojej aplikacji użyć podziału kodu może być nieco skomplikowane.
231+
Chcesz mieć pewność, że wybierasz miejsca, które równomiernie podzielą twoje pakiety,
232+
ale nie chcesz naruszyć doświadczeń użytkownika.
220233

221-
A good place to start is with routes. Most people on the web are used to
222-
page transitions taking some amount of time to load. You also tend to be
223-
re-rendering the entire page at once so your users are unlikely to be
224-
interacting with other elements on the page at the same time.
234+
Dobrym miejscem do rozpoczęcia są trasy (routes). Większość osób w sieci jest przywyczajona
235+
do przechodzenia między stronami, które wymaga pewnego czasu. Jest także trend ponownego
236+
renderowania całej strony, więc uzytkownicy raczej nie będą wchodzić w inną interakcje
237+
w tym samym czasie.
225238

226-
Here's an example of how to setup route-based code splitting into your app using
227-
libraries like [React Router](https://reacttraining.com/react-router/) with `React.lazy`.
239+
Oto przykład konfiguracji dzielenia kodu w twojej aplikacji opartej na trasach za pomoca
240+
bibliotek takich jak [React Router](https://reacttraining.com/react-router/) wraz z `React.lazy`.
228241

229242
```js
230243
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
@@ -245,9 +258,12 @@ const App = () => (
245258
);
246259
```
247260

248-
## Named Exports {#named-exports}
261+
## Eksport nazw {#named-exports}
249262

250-
`React.lazy` currently only supports default exports. If the module you want to import uses named exports, you can create an intermediate module that reexports it as the default. This ensures that treeshaking keeps working and that you don't pull in unused components.
263+
`React.lazy` obecnie obsługuje tylko domyślne eksporty. Jeśli moduł, który chcesz zaimportowac,
264+
używa nazwanych eksportów, możesz utworzyć moduł pośredni, który ponownie eksportuje je jako
265+
domyślny eksport. Gwarantuje to, utrzymanie działającego drzewa oraz niepobieranie nieuzywanych
266+
komponentów.
251267

252268
```js
253269
// ManyComponents.js

0 commit comments

Comments
 (0)