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: README.md
+36-25Lines changed: 36 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,7 @@ Because all the methods of i18n of JS frontend apps (particularly loading/delive
12
12
13
13
## What it does
14
14
15
-
#### Simple example of bundling language packs.
16
-
17
-
Say you have tree components in your application that you going to bundle with webpack.
15
+
Here is nominal case of bundling language packs. Say you have tree components in your application that you going to bundle with webpack.
18
16
19
17
```
20
18
- app/A
@@ -37,7 +35,7 @@ app/C/dict/
37
35
ru.json
38
36
```
39
37
40
-
Say due to your app config webpack produces two bundles:
38
+
Say you structured the app and configured Webpack to produces two bundles:
41
39
-`bundle-AB` - contains `A` and `B` components
42
40
-`bundle-C` - separate bundle that contains `C` component.
43
41
@@ -51,9 +49,9 @@ bundle-C.en.lp.js - will contain `ru` dictionaries for C
51
49
bundle-C.ru.lp.js - will contain `en` dictionaries for C
52
50
```
53
51
54
-
Particular language bundle **will be loaded dynamically on demand** when it will be accessed from it's parent bundle code. If language is not used, language data bundles are not loaded.
52
+
Particular language bundle **will be loaded dynamically on demand** when it will be accessed from it's parent bundle code (see below). If language is not used, language data bundles are not loaded.
55
53
56
-
As stated above, `LP-Loader` can be used to bundle this way not only language specific dictionaries, but **any *labeled* sets of *data* or *code*** that should be loaded dynamically on demand.
54
+
As stated above, `LP-Loader` can be used to bundle this way not only language specific dictionaries, but **any *labeled* sets of *data* or *code*** that need to be loaded on demand.
57
55
58
56
## Installation
59
57
@@ -64,17 +62,17 @@ As stated above, `LP-Loader` can be used to bundle this way not only language sp
64
62
yarn add lp-loader [--dev]
65
63
```
66
64
67
-
## Configuration
65
+
## Usage
68
66
69
-
This is the example with TypeScript based dictionaries, so you have to have following files:
67
+
This is the example with TypeScript based dictionaries (because using TypeScript for language dictionaries data is super cool). So you have to have following files:
70
68
71
69
```
72
70
app/A/
73
71
A.ts - component file
74
72
app/A/dict/
75
-
en.ts - dict for `english` language
76
-
ru.ts - dict for `russian` language
77
-
index.ts - lp-index file
73
+
en.ts - dictionary file for `English` language
74
+
ru.ts - dictionary file `Russian` language
75
+
index.ts - dictionary index file
78
76
79
77
```
80
78
@@ -83,13 +81,28 @@ You need to have an index file (`app/A/dict/index.ts`) for each of your dictiona
83
81
In case of `TS` to have correct and useful dictionary typings code like this should be put inside:
84
82
85
83
```ts
86
-
typeDict= { /* Here goes a dictionary structure */ }
[*There are example configs in corresponding webpackX folders*](./webpack4/webpack.config.ts). Actually no difference between Webpack 3 and 4.
164
-
165
176
## How it works
166
177
167
-
It is quite simple. Loader finds chunk parents of the dictionary index, and generates special code to allow loading requested dictionary data on demand (via `Promise` based API).
178
+
It is quite simple. Loader finds chunk parents of the dictionary index, and generates special code that allow loading requested data on demand via `Promise` based API.
168
179
169
180
[*You may want to look at the loader's code.*](./src/lp-loader.ts)
0 commit comments