Skip to content

Commit 9448d55

Browse files
author
Dennis Miasoutov
committed
Add bundle analyzer, no server pollution on client.
1 parent 036e461 commit 9448d55

File tree

16 files changed

+175
-54
lines changed

16 files changed

+175
-54
lines changed

app/entry/index.dev.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// @ts-ignore
22
import * as AppModule from "injected-app-module";
33
import { hot } from "react-hot-loader/root";
4+
import { logger } from "redux-logger";
45

5-
export default hot(AppModule.App);
6+
const App = hot(AppModule.App);
7+
const devMiddlewares = [logger];
8+
9+
export { App, devMiddlewares };

app/entry/index.prod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// @ts-nocheck
22
import * as AppModule from "injected-app-module";
3-
export default AppModule.App;
3+
4+
const App = AppModule.App;
5+
const devMiddlewares = [];
6+
7+
export { App, devMiddlewares };

app/esm/domain-task.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// custom implementation
2+
import fetch from "isomorphic-fetch";
3+
4+
function addTask(promise: Promise<any>) {
5+
// do nothing
6+
}
7+
8+
export { fetch, addTask };

app/flavors/basic/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { AppProps } from "../../common";
33
import { HelmetWrapper } from "../../components";
44

55
// @ts-ignore
6-
import InjectedApp from "injected-app-entry";
6+
import * as InjectedAppModule from "injected-app-entry";
77

88
export class App extends React.Component<AppProps> {
99
public render(): React.ReactNode {
1010
return (
1111
<HelmetWrapper helmetContext={this.props.context.helmetContext}>
12-
<InjectedApp />
12+
<InjectedAppModule.App />
1313
</HelmetWrapper>
1414
);
1515
}

app/flavors/basic/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from "./createContext";
2-
export * from "./render";
32
export * from "./app";
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from "../router-redux/createContext";
22
export * from "../router-redux/app";
3-
export * from "./render";

app/flavors/router-redux-async/render.tsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
baseUrl as domainTaskBaseUrl,
33
run as domainTaskRun,
4-
} from "domain-task/main";
4+
} from "domain-task";
55
import { createMemoryHistory } from "history";
66
import * as React from "react";
77
import { renderToStaticMarkup, renderToString } from "react-dom/server";
@@ -26,37 +26,36 @@ export function render(callback: RenderCallback, props: RenderFuncProps): void {
2626
new Error(`Cannot complete prerendering withing ${timeout} second`),
2727
);
2828
}, timeout * 1000);
29-
domainTaskRun(
30-
() => {
31-
domainTaskBaseUrl(props.baseUrl);
32-
renderToString(app);
33-
},
34-
/* completion callback */ errorOrNothing => {
35-
clearTimeout(timeoutTimer);
36-
if (firstError) {
37-
return;
38-
}
39-
if (errorOrNothing) {
40-
firstError = errorOrNothing;
41-
callback(errorOrNothing);
42-
} else {
43-
const markup = renderToString(app);
4429

45-
const htmlProps: HelmetHtmlProps = {
46-
assets: props.assets,
47-
context,
48-
inlineScripts: props.inlineScripts,
49-
markup,
50-
};
30+
const completionCallback = errorOrNothing => {
31+
clearTimeout(timeoutTimer);
32+
if (firstError) {
33+
return;
34+
}
35+
if (errorOrNothing) {
36+
firstError = errorOrNothing;
37+
callback(errorOrNothing);
38+
} else {
39+
const markup = renderToString(app);
5140

52-
const html = renderToStaticMarkup(<HelmetHtml {...htmlProps} />);
41+
const htmlProps: HelmetHtmlProps = {
42+
assets: props.assets,
43+
context,
44+
inlineScripts: props.inlineScripts,
45+
markup,
46+
};
5347

54-
callback(undefined, {
55-
html,
56-
});
57-
}
58-
},
59-
);
48+
const html = renderToStaticMarkup(<HelmetHtml {...htmlProps} />);
49+
50+
callback(undefined, {
51+
html,
52+
});
53+
}
54+
};
55+
domainTaskRun(() => {
56+
domainTaskBaseUrl(props.baseUrl);
57+
renderToString(app);
58+
}, completionCallback);
6059
} catch (error) {
6160
callback(error);
6261
}

app/flavors/router-redux/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { AppProps } from "../../common";
55
import { HelmetWrapper } from "../../components";
66

77
// @ts-ignore
8-
import InjectedApp from "injected-app-entry";
8+
import * as InjectedAppModule from "injected-app-entry";
99

1010
export class App extends React.Component<AppProps> {
1111
public render(): React.ReactNode {
1212
return (
1313
<HelmetWrapper helmetContext={this.props.context.helmetContext}>
1414
<Provider store={this.props.context.store}>
1515
<ConnectedRouter history={this.props.context.history}>
16-
<InjectedApp />
16+
<InjectedAppModule.App />
1717
</ConnectedRouter>
1818
</Provider>
1919
</HelmetWrapper>

app/flavors/router-redux/createContext.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { connectRouter } from "connected-react-router";
44
import { routerMiddleware } from "connected-react-router";
55
import { createBrowserHistory, History } from "history";
66
import * as Redux from "redux";
7-
import { logger } from "redux-logger";
87
import { Context } from "../../common";
98

109
// @ts-ignore
10+
import { devMiddlewares } from "injected-app-entry";
1111
import { middlewares, reducers } from "injected-app-module/store";
1212

1313
export function createContext(abstractHistory?: History): Context {
@@ -35,11 +35,8 @@ function configureStore(history: History, initialState?: any): any {
3535
const rootReducers = createRootReducer(history, reducers);
3636

3737
// Adding logger and router to middlewares
38-
const defaultMiddlewares: Redux.Middleware = [];
3938
const isSsr = typeof window === "undefined";
40-
if (!isSsr) {
41-
defaultMiddlewares.push(logger);
42-
}
39+
const defaultMiddlewares: Redux.Middleware = !isSsr ? devMiddlewares : [];
4340
defaultMiddlewares.push(routerMiddleware(history));
4441

4542
const pipeline = Redux.applyMiddleware(...defaultMiddlewares, ...middlewares);

app/flavors/router-redux/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from "./createContext";
2-
export * from "./render";
32
export * from "./app";

0 commit comments

Comments
 (0)