diff --git a/CHANGELOG.md b/CHANGELOG.md
index bbc6caf..15b170e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## HEAD
+
+- Allow for base path injection in `htmlSource`.
+
## 0.4.0
- **Bug:**: Fixes the way Underreact handles root relative urls.
diff --git a/README.md b/README.md
index 50ee594..3f97b34 100644
--- a/README.md
+++ b/README.md
@@ -200,26 +200,55 @@ Underreact is intended for single-page apps, so you only need one HTML page. If
You have 2 choices:
-1. **Preferred:** Provide the [`htmlSource`] configuration option, which is an HTML string or a Promise that resolves to an HTML string.
+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.
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 `
`.
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 `
diff --git a/lib/config/validate-config.js b/lib/config/validate-config.js
index cb9b4cc..c963c88 100644
--- a/lib/config/validate-config.js
+++ b/lib/config/validate-config.js
@@ -13,7 +13,7 @@ function validateConfig(rawConfig = {}) {
compileNodeModules: v.oneOfType(v.boolean, v.arrayOf(v.string)),
devServerHistoryFallback: v.boolean,
hot: v.boolean,
- htmlSource: v.oneOfType(validatePromise, v.string),
+ htmlSource: v.oneOfType(validatePromise, v.string, v.func),
jsEntry: validateAbsolutePaths,
liveReload: v.boolean,
environmentVariables: v.plainObject,
diff --git a/lib/webpack-config/generate-html-template.js b/lib/webpack-config/generate-html-template.js
index 59d7566..851a7bf 100644
--- a/lib/webpack-config/generate-html-template.js
+++ b/lib/webpack-config/generate-html-template.js
@@ -7,7 +7,13 @@ module.exports = function generateHtmlTemplate({
webpackCompilation,
publicPath
}) {
- return Promise.resolve(urc.htmlSource).then(html =>
+ let htmlSource = urc.htmlSource;
+
+ if (typeof urc.htmlSource === 'function') {
+ htmlSource = urc.htmlSource({ basePath: urc.getBasePathEnv() });
+ }
+
+ return Promise.resolve(htmlSource).then(html =>
html
.replace(
'',