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
{{ message }}
This repository was archived by the owner on Dec 19, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+36-5Lines changed: 36 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,26 +200,55 @@ Underreact is intended for single-page apps, so you only need one HTML page. If
200
200
201
201
You have 2 choices:
202
202
203
-
1.**Preferred:** Provide the [`htmlSource`] configuration option, which is an HTML stringor a Promise that resolves to an HTML string.
203
+
1.**Preferred:** Provide the [`htmlSource`] configuration option, which is an HTML string, a Promise or a Function returning HTML string or promise, that resolves to an HTML string.
204
204
2. Provide no HTML-rendering function and let Underreact use the default, development-only HTML document. *You should only do this for prototyping and early development*: for production projects, you'll definitely want to define your own HTML, if only for the `<title>`.
205
205
206
206
If you provide a Promise for [`htmlSource`], you can use any async I/O you need to put together the page. For example, you could read JS files and inject their code directly into `<script>` tags, or inject CSS into `<style>` tags. Or you could make an HTTP call to fetch dynamic data and inject it into the page with a `<script>` tag, so it's available to your React app.
207
207
208
+
If you provide a Function for [`htmlSource`], Underreact would call it with the named parameter `basePath`. This gives you the flexibility to load assets with a root relative URL. The example below shows how to load a favicon from your `public` directory:
209
+
210
+
```js
211
+
// underreact.config.js
212
+
module.exports= {
213
+
/**
214
+
* @param{Object}opts
215
+
* @param{Webpack}opts.basePath - the normalized value of your site's base path
216
+
* @returns{Promise<string> | string}
217
+
*/
218
+
htmlSource: ({ basePath }) =>`
219
+
<!DOCTYPE html>
220
+
<html lang="en">
221
+
<head>
222
+
<meta charset="utf-8">
223
+
<title>Words that rhyme with fish</title>
224
+
<meta name="description" content="A website about words that rhyme with fish, like plish">
@@ -460,7 +489,7 @@ Enable hot module reloading of Underreact. Read ["How do I enable hot module rel
460
489
461
490
### htmlSource
462
491
463
-
Type: `string`\|`Promise<string>`. Default:[see the default HTML](https://github.com/mapbox/underreact/blob/next/lib/default-html.js).
492
+
Type: `string`\|`Promise<string>`\|`Function<string | Promise<string>>`. Default:[see the default HTML](https://github.com/mapbox/underreact/blob/next/lib/default-html.js).
464
493
465
494
The HTML template for your app, or a Promise that resolves to it. Read ["Defining your HTML"](#defining-your-html) for more details.
466
495
@@ -543,6 +572,8 @@ Path to the base directory on the domain where the site will be deployed. The de
543
572
544
573
This normalization behaviour comes in handy when writing statements like `process.env.BASE_PATH + '/my-path'`. Read ["How do I include SVGs, images, and videos?"](#how-do-i-include-svgs-images-and-videos).
545
574
575
+
Underreact also passes this as a named parameter to the [`htmlSource`] function. Read ["Defining your HTML"](#defining-your-html) for more details.
576
+
546
577
**Tip**: There's a good chance your app isn't at the root of your domain. So this option represents the path of your site *within* that domain. For example, if your app is at `https://www.special.com/ketchup/*`, you should set `siteBasePath: '/ketchup'`.
0 commit comments