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
@@ -156,6 +157,7 @@ npm run serve -- --server config
156
157
Preact CLI in order to follow [PRPL] pattern renders initial route (`/`) into generated static `index.html` - this ensures that users get to see your page before any JavaScript is run, and thus providing users with slow devices or poor connection your website's content much faster.
157
158
158
159
Preact CLI does this by rendering your app inside node - this means that we don't have access to DOM or other global variables available in browsers, similar how it would be in server-side rendering scenarios. In case you need to rely on browser APIs you could:
160
+
159
161
- drop out of prerendering by passing `--no-prerender` flag to `preact build`,
160
162
- write your code in a way that supports server-side rendering by wrapping code that requires browser's APIs in conditional statements `if (typeof window !== "undefined") { ... }` ensuring that on server those lines of code are never reached. Alternatively you could use a helper library like [window-or-global](https://www.npmjs.com/package/window-or-global).
161
163
@@ -192,7 +194,7 @@ To customize Babel, you have two options:
192
194
193
195
#### Webpack
194
196
195
-
To customize webpack create ```preact.config.js``` file which exports function that will change webpack's config.
197
+
To customize webpack create `preact.config.js` file which exports function that will change webpack's config.
196
198
197
199
```js
198
200
/**
@@ -203,12 +205,12 @@ To customize webpack create ```preact.config.js``` file which exports function t
203
205
* @param{object}env - options passed to CLI.
204
206
* @param{WebpackConfigHelpers}helpers - object with useful helpers when working with config.
205
207
**/
206
-
exportdefaultfunction(config, env, helpers) {
207
-
/** you can change config here **/
208
+
exportdefaultfunction(config, env, helpers) {
209
+
/** you can change config here **/
208
210
}
209
211
```
210
212
211
-
See [WebpackConfigHelpers] docs for more info on ```helpers``` argument which contains methods to find various parts of configuration. Additionally see our [recipes wiki] containing examples on how to change webpack configuration.
213
+
See [WebpackConfigHelpers] docs for more info on `helpers` argument which contains methods to find various parts of configuration. Additionally see our [recipes wiki] containing examples on how to change webpack configuration.
212
214
213
215
#### Prerender multiple routes
214
216
@@ -218,12 +220,15 @@ The format required for defining your routes is an array of objects with a `url`
218
220
219
221
```js
220
222
// prerender-urls.json
221
-
[{
222
-
"url":"/",
223
-
"title":"Homepage"
224
-
}, {
225
-
"url":"/route/random"
226
-
}]
223
+
[
224
+
{
225
+
url:'/',
226
+
title:'Homepage',
227
+
},
228
+
{
229
+
url:'/route/random',
230
+
},
231
+
];
227
232
```
228
233
229
234
You can customise the path of `prerender-urls.json` by using the flag `--prerenderUrls`.
0 commit comments