-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By also bundling the node integrator with webpack-dev-middleware we can avoid having to restart the demo server when changes to server-side rendered demos are made. This is based on https://github.com/webpack/webpack-dev-middleware#server-side-rendering. fixes #250
- Loading branch information
1 parent
08f4f52
commit ddb29bf
Showing
25 changed files
with
735 additions
and
266 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as FeatureHubReact from '@feature-hub/react'; | ||
import * as React from 'react'; | ||
|
||
export const externals = { | ||
react: React, | ||
'@feature-hub/react': FeatureHubReact, | ||
}; |
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
12 changes: 6 additions & 6 deletions
12
packages/demos/src/feature-app-in-feature-app/integrator.node.tsx
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {Css} from '@feature-hub/react'; | ||
import express from 'express'; | ||
import webpack from 'webpack'; | ||
|
||
export interface AppRendererOptions { | ||
port: number; | ||
req: express.Request; | ||
} | ||
|
||
export interface AppRendererResult { | ||
html: string; | ||
serializedStates?: string; | ||
stylesheetsForSsr?: Map<string, Css>; | ||
urlsForHydration?: Set<string>; | ||
} | ||
|
||
export type AppRenderer = ( | ||
options: AppRendererOptions | ||
) => Promise<AppRendererResult>; | ||
|
||
// tslint:disable-next-line:no-any | ||
function evalNodeSource(source: string): any { | ||
const mod = {exports: {}}; | ||
|
||
// tslint:disable-next-line:function-constructor | ||
Function('module', 'exports', 'require', source)(mod, mod.exports, require); | ||
|
||
return mod.exports; | ||
} | ||
|
||
export const nodeIntegratorFilename = 'integrator.node.js'; | ||
|
||
export function loadNodeIntegrator( | ||
res: express.Response | ||
): AppRenderer | undefined { | ||
try { | ||
const outputFileSystem: webpack.InputFileSystem & webpack.OutputFileSystem = | ||
res.locals.webpack.devMiddleware.outputFileSystem; | ||
|
||
const {outputPath} = res.locals.webpack.devMiddleware.stats.toJson(); | ||
|
||
const source = outputFileSystem | ||
.readFileSync(outputFileSystem.join(outputPath, nodeIntegratorFilename)) | ||
.toString(); | ||
|
||
return evalNodeSource(source).default; | ||
} catch { | ||
return undefined; | ||
} | ||
} |
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.