Skip to content

Commit

Permalink
refactor(v2): replace EJS with Eta for SSR generation (#2684)
Browse files Browse the repository at this point in the history
* Replace EJS with Eta for SSR generation

* Format with Prettier

* Remove ejs alias

* Don't autotrim, Terser will minify already

* Don't autoTrim, files are HTML-minified later

* Equivalent of rmWhitespace option for Eta

* Update Eta version and add rmWhitespace

* Format with Prettier
  • Loading branch information
nebrelbug authored May 5, 2020
1 parent df815db commit 368eb42
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
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.1",
"express": "^4.17.1",
"fs-extra": "^8.1.0",
"globby": "^10.0.1",
Expand Down
5 changes: 3 additions & 2 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,6 +77,7 @@ export default async function render(locals) {
version: packageJson.version,
},
{
name: 'ssr-template',
rmWhitespace: true,
},
);
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 @@ -6194,11 +6194,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 @@ -6700,6 +6695,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.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/eta/-/eta-1.1.1.tgz#acd575025233488a66870b02223001d4cd467441"
integrity sha512-YRchTAXZZrrJVmlAwmLHuKmlHNJ2hO0uen8LsDqvH5kknRjh0ef+Y9kInENygCgvu7FQNJBpbyDChfMo8f5Qgw==

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

0 comments on commit 368eb42

Please sign in to comment.