Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(entryObj).forEach(entry => {
// get document html string
const pageSource = '' + renderToString(createElement(documentElement, {
publicPath,
styles: [],
scripts: [`web/${entry}.js`]
}));
// insert html file
compilation.assets[`web/${entry}.html`] = new RawSource(pageSource);
});
if (skeletonTemplate) {
_htmlValue = _htmlValue.replace(
'',
``
);
}
const jsTagStr = _htmlAssets.js.map(src => ``).join('') || '';
const cssTagStr = _htmlAssets.css.map(src => ``).join('') || '';
_htmlValue = _htmlValue
.replace('', `${cssTagStr}`)
.replace('', `${jsTagStr}`);
} else {
// Use document.js
_htmlPath = this.documentJsFilePath;
_htmlValue = renderer.renderToString(
createElement(interopRequire(eval(fs.readFileSync(this.tempHtmlFilePath, 'utf-8'))), {
scripts: _htmlAssets.js,
styles: _htmlAssets.css,
title: title,
pageData: JSON.stringify({}),
pageHtml: appShellTemplate
})
);
if (skeletonTemplate) {
_htmlValue = _htmlValue.replace(
'${skeletonTemplate}
webpack(getShellConfig(pathConfig)).run((err) => {
if (err) {
console.error(err);
return false;
}
const shellJsPath = path.resolve(pathConfig.appBuild, './shells.js');
const component = require(shellJsPath).default;
this.AppShellTemplate = renderer.renderToString(createElement(component, {}, createElement('div', { id: 'root-page' })));
fs.unlinkSync(shellJsPath);
callback();
});
});
let pageData;
let pageHtml;
if (shell && shell.component) {
const result = await renderShell({
ctx,
shell,
component,
renderOpts
});
pageData = result.data;
pageHtml = result.html;
} else {
pageData = await getInitialProps(component, ctx);
const pageElement = createElement(component, pageData);
pageHtml = renderer.renderToString(pageElement, renderOpts);
}
const documentComponent = document.component || Document;
const pageTitle = title || document.title;
const documentData = await getInitialProps(documentComponent, ctx);
const documentElement = createElement(documentComponent, {
title: pageTitle,
pageHtml,
pageData: JSON.stringify(pageData),
styles,
scripts,
...documentData
});
const html = '' + renderer.renderToString(documentElement, renderOpts);
module.exports = async function (viewCtx, next) {
const { Component, props } = viewCtx;
const instance = Rax.createElement(Component, props);
viewCtx.html += RaxServer.renderToString(instance);
await next();
};
.add(`Rax(${raxPkg.version})#renderToString`, function() {
raxRenderToString(Rax.createElement(RaxApp, data));
})
.add(`Inferno(${infernoPkg.version})#renderToString`, function() {
shell,
component,
renderOpts
} = options;
const shellComponent = shell.component;
const data = await getInitialProps(shellComponent, {
...ctx,
Component: component
});
const shellElement = createElement(shellComponent, {
...data,
Component: component
});
const html = renderer.renderToString(shellElement, renderOpts);
return {
data,
html
};
}
module.exports = (req, res) => {
res.type('text/html').code(200);
res.send(
renderToString(render())
);
};
pageHtml = renderer.renderToString(pageElement, renderOpts);
}
const documentComponent = document.component || Document;
const pageTitle = title || document.title;
const documentData = await getInitialProps(documentComponent, ctx);
const documentElement = createElement(documentComponent, {
title: pageTitle,
pageHtml,
pageData: JSON.stringify(pageData),
styles,
scripts,
...documentData
});
const html = '' + renderer.renderToString(documentElement, renderOpts);
return html;
}
module.exports = () => renderToString(factory(createElement))