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

refactor(v2): replace EJS with Eta for SSR generation #2684

Merged
merged 10 commits into from
May 5, 2020
2 changes: 1 addition & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"core-js": "^2.6.5",
"css-loader": "^3.4.2",
"del": "^5.1.0",
"ejs": "^3.0.2",
"eta": "^1.1.0",
"express": "^4.17.1",
"fs-extra": "^8.1.0",
"globby": "^10.0.1",
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus/src/client/serverEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import ejs from 'ejs';
import * as eta from 'eta';
import React from 'react';
import {StaticRouter} from 'react-router-dom';
import ReactDOMServer from 'react-dom/server';
Expand Down Expand Up @@ -61,7 +61,7 @@ export default async function render(locals) {
const scripts = (bundles.js || []).map((b) => b.file);
const {baseUrl} = locals;

const renderedHtml = ejs.render(
const renderedHtml = eta.render(
ssrTemplate.trim(),
{
appHtml,
Expand All @@ -77,7 +77,8 @@ export default async function render(locals) {
version: packageJson.version,
},
{
rmWhitespace: true,
autoTrim: false,
name: 'ssr-template',
},
);

Expand Down
30 changes: 15 additions & 15 deletions packages/docusaurus/src/client/templates/ssr.html.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@

module.exports = `
<!DOCTYPE html>
<html <%- htmlAttributes %>>
<html <%~ it.htmlAttributes %>>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="generator" content="Docusaurus v<%= version %>">
<%- headTags %>
<% metaAttributes.forEach((metaAttribute) => { %>
<%- metaAttribute %>
<meta name="generator" content="Docusaurus v<%= it.version %>">
<%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
<% }); %>
<% stylesheets.forEach((stylesheet) => { %>
<link rel="stylesheet" type="text/css" href="<%= baseUrl %><%= stylesheet %>" />
<% it.stylesheets.forEach((stylesheet) => { %>
<link rel="stylesheet" type="text/css" href="<%= it.baseUrl %><%= stylesheet %>" />
<% }); %>
<% scripts.forEach((script) => { %>
<link rel="preload" href="<%= baseUrl %><%= script %>" as="script">
<% it.scripts.forEach((script) => { %>
<link rel="preload" href="<%= it.baseUrl %><%= script %>" as="script">
<% }); %>
</head>
<body <%- bodyAttributes %>>
<%- preBodyTags %>
<body <%~ it.bodyAttributes %>>
<%~ it.preBodyTags %>
<div id="__docusaurus">
<%- appHtml %>
<%~ it.appHtml %>
</div>
<% scripts.forEach((script) => { %>
<script type="text/javascript" src="<%= baseUrl %><%= script %>"></script>
<% it.scripts.forEach((script) => { %>
<script type="text/javascript" src="<%= it.baseUrl %><%= script %>"></script>
<% }); %>
<%- postBodyTags %>
<%~ it.postBodyTags %>
</body>
</html>
`;
2 changes: 0 additions & 2 deletions packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export function createBaseConfig(
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
symlinks: true,
alias: {
// https://stackoverflow.com/a/55433680/6072730
ejs: 'ejs/ejs.min.js',
'@site': siteDir,
'@generated': generatedFilesDir,
'@docusaurus': path.resolve(__dirname, '../client/exports'),
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6199,11 +6199,6 @@ ejs@^2.6.1:
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba"
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==

ejs@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.0.2.tgz#745b01cdcfe38c1c6a2da3bbb2d9957060a31226"
integrity sha512-IncmUpn1yN84hy2shb0POJ80FWrfGNY0cxO9f4v+/sG7qcBvAtVWUA1IdzY/8EYUmOVhoKJVdJjNd3AZcnxOjA==

electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.322:
version "1.3.322"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.322.tgz#a6f7e1c79025c2b05838e8e344f6e89eb83213a8"
Expand Down Expand Up @@ -6705,6 +6700,11 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

eta@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/eta/-/eta-1.1.0.tgz#e43c1aa6ea1d727b59c75e928a19a7e3019efb88"
integrity sha512-uRJ5adkcETpARCpAkN56t13AjZePSA99A/OgNwSdc/wCthr8l+uEcvbx53R4rutwmfSBlF6VOYq7vXgooqVJNQ==

etag@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
Expand Down