Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow including files just before manager.bundle.js #1134

Merged
merged 12 commits into from
Jun 7, 2017
3 changes: 2 additions & 1 deletion app/react/src/server/index.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const managerUrlsFromAssets = assets => {
};

export default function(data) {
const { assets, publicPath } = data;
const { assets, publicPath, bodyScript } = data;

const managerUrls = managerUrlsFromAssets(assets);

Expand Down Expand Up @@ -73,6 +73,7 @@ export default function(data) {
</head>
<body style="margin: 0;">
<div id="root"></div>
${bodyScript}
<script src="${url.resolve(publicPath, managerUrls.js)}"></script>
</body>
</html>
Expand Down
5 changes: 3 additions & 2 deletions app/react/src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getBaseConfig from './config/webpack.config';
import loadConfig from './config';
import getIndexHtml from './index.html';
import getIframeHtml from './iframe.html';
import { getHeadHtml, getMiddleware } from './utils';
import { getHeadHtml, getBodyScript, getMiddleware } from './utils';

export default function(configDir) {
// Build the webpack configuration using the `getBaseConfig`
Expand Down Expand Up @@ -36,7 +36,8 @@ export default function(configDir) {
middlewareFn(router);

router.get('/', (req, res) => {
res.send(getIndexHtml({ publicPath }));
const bodyScript = getBodyScript(configDir)
res.send(getIndexHtml({ publicPath, bodyScript }));
});

router.get('/iframe.html', (req, res) => {
Expand Down
11 changes: 11 additions & 0 deletions app/react/src/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export function getHeadHtml(configDirPath) {
return headHtml;
}

export function getBodyScript(configDirPath) {
const scriptPath = path.resolve(configDirPath, 'bodyscript.html');
let scriptHtml = '';
if (fs.existsSync(scriptPath)) {
scriptHtml = fs.readFileSync(scriptPath, 'utf8');
}

return scriptHtml;
}


export function getEnvConfig(program, configEnv) {
Object.keys(configEnv).forEach(fieldName => {
const envVarName = configEnv[fieldName];
Expand Down