Skip to content

Commit 49bc32e

Browse files
committed
Allow including a js files just before manager.bundle.js
Context & Why? The process went like this: 1. Why are storybook's build times so slow (5 sec or more)? 2. Lets try adding the webpack dll plugin 3. Oh wait, now I need to include a vendor.js (it has the react bits) prior to storybook 4. This commit 5. Now build times are sub 200ms.
1 parent fe66b26 commit 49bc32e

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

app/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@storybook/react",
3-
"version": "3.0.0-rc.0",
2+
"name": "@enjoylife/react",
3+
"version": "3.0.0-rc.1",
44
"description": "Storybook for React: Develop React Component in isolation with Hot Reloading.",
55
"license": "MIT",
66
"main": "dist/client/index.js",

app/react/src/server/index.html.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const managerUrlsFromAssets = assets => {
2828
};
2929

3030
export default function(data) {
31-
const { assets, publicPath } = data;
31+
const { assets, publicPath, bodyScript } = data;
3232

3333
const managerUrls = managerUrlsFromAssets(assets);
3434

@@ -73,6 +73,7 @@ export default function(data) {
7373
</head>
7474
<body style="margin: 0;">
7575
<div id="root"></div>
76+
${bodyScript}
7677
<script src="${url.resolve(publicPath, managerUrls.js)}"></script>
7778
</body>
7879
</html>

app/react/src/server/middleware.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import getBaseConfig from './config/webpack.config';
66
import loadConfig from './config';
77
import getIndexHtml from './index.html';
88
import getIframeHtml from './iframe.html';
9-
import { getHeadHtml, getMiddleware } from './utils';
9+
import { getHeadHtml, getBodyScript, getMiddleware } from './utils';
1010

1111
export default function(configDir) {
1212
// Build the webpack configuration using the `getBaseConfig`
@@ -36,7 +36,8 @@ export default function(configDir) {
3636
middlewareFn(router);
3737

3838
router.get('/', (req, res) => {
39-
res.send(getIndexHtml({ publicPath }));
39+
const bodyScript = getBodyScript(configDir)
40+
res.send(getIndexHtml({ publicPath, bodyScript }));
4041
});
4142

4243
router.get('/iframe.html', (req, res) => {

app/react/src/server/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ export function getHeadHtml(configDirPath) {
1515
return headHtml;
1616
}
1717

18+
export function getBodyScript(configDirPath) {
19+
const scriptPath = path.resolve(configDirPath, 'bodyscript.html');
20+
let scriptHtml = '';
21+
if (fs.existsSync(scriptPath)) {
22+
scriptHtml = fs.readFileSync(scriptPath, 'utf8');
23+
}
24+
25+
return scriptHtml;
26+
}
27+
28+
1829
export function getEnvConfig(program, configEnv) {
1930
Object.keys(configEnv).forEach(fieldName => {
2031
const envVarName = configEnv[fieldName];

0 commit comments

Comments
 (0)