-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from rkostrzewski/feature/webpack-ssr
feature: Prerender using webpack
- Loading branch information
Showing
25 changed files
with
420 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function(source, map) { | ||
this.callback(null, source, map); | ||
}; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { resolve } from 'path'; | ||
|
||
export default function prerender(outputDir, params) { | ||
params = params || {}; | ||
|
||
let entry = resolve(outputDir, './ssr-build/ssr-bundle.js'), | ||
url = params.url || '/'; | ||
|
||
global.location = { href:url, pathname:url }; | ||
global.history = {}; | ||
|
||
let m = require(entry), | ||
app = m && m.default || m; | ||
|
||
if (typeof app!=='function') { | ||
// eslint-disable-next-line no-console | ||
console.warn('Entry does not export a Component function/class, aborting prerendering.'); | ||
return ''; | ||
} | ||
|
||
let preact = require('preact'), | ||
renderToString = require('preact-render-to-string'); | ||
|
||
let html = renderToString(preact.h(app, { url })); | ||
|
||
return html; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.