mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
refactor(v2): replace EJS with Eta for SSR generation (#2684)
* 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
This commit is contained in:
parent
df815db031
commit
368eb4279f
5 changed files with 24 additions and 25 deletions
|
@ -53,7 +53,7 @@
|
||||||
"core-js": "^2.6.5",
|
"core-js": "^2.6.5",
|
||||||
"css-loader": "^3.4.2",
|
"css-loader": "^3.4.2",
|
||||||
"del": "^5.1.0",
|
"del": "^5.1.0",
|
||||||
"ejs": "^3.0.2",
|
"eta": "^1.1.1",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"globby": "^10.0.1",
|
"globby": "^10.0.1",
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ejs from 'ejs';
|
import * as eta from 'eta';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {StaticRouter} from 'react-router-dom';
|
import {StaticRouter} from 'react-router-dom';
|
||||||
import ReactDOMServer from 'react-dom/server';
|
import ReactDOMServer from 'react-dom/server';
|
||||||
|
@ -61,7 +61,7 @@ export default async function render(locals) {
|
||||||
const scripts = (bundles.js || []).map((b) => b.file);
|
const scripts = (bundles.js || []).map((b) => b.file);
|
||||||
const {baseUrl} = locals;
|
const {baseUrl} = locals;
|
||||||
|
|
||||||
const renderedHtml = ejs.render(
|
const renderedHtml = eta.render(
|
||||||
ssrTemplate.trim(),
|
ssrTemplate.trim(),
|
||||||
{
|
{
|
||||||
appHtml,
|
appHtml,
|
||||||
|
@ -77,6 +77,7 @@ export default async function render(locals) {
|
||||||
version: packageJson.version,
|
version: packageJson.version,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: 'ssr-template',
|
||||||
rmWhitespace: true,
|
rmWhitespace: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,31 +7,31 @@
|
||||||
|
|
||||||
module.exports = `
|
module.exports = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html <%- htmlAttributes %>>
|
<html <%~ it.htmlAttributes %>>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<meta name="generator" content="Docusaurus v<%= version %>">
|
<meta name="generator" content="Docusaurus v<%= it.version %>">
|
||||||
<%- headTags %>
|
<%~ it.headTags %>
|
||||||
<% metaAttributes.forEach((metaAttribute) => { %>
|
<% it.metaAttributes.forEach((metaAttribute) => { %>
|
||||||
<%- metaAttribute %>
|
<%~ metaAttribute %>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
<% stylesheets.forEach((stylesheet) => { %>
|
<% it.stylesheets.forEach((stylesheet) => { %>
|
||||||
<link rel="stylesheet" type="text/css" href="<%= baseUrl %><%= stylesheet %>" />
|
<link rel="stylesheet" type="text/css" href="<%= it.baseUrl %><%= stylesheet %>" />
|
||||||
<% }); %>
|
<% }); %>
|
||||||
<% scripts.forEach((script) => { %>
|
<% it.scripts.forEach((script) => { %>
|
||||||
<link rel="preload" href="<%= baseUrl %><%= script %>" as="script">
|
<link rel="preload" href="<%= it.baseUrl %><%= script %>" as="script">
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</head>
|
</head>
|
||||||
<body <%- bodyAttributes %>>
|
<body <%~ it.bodyAttributes %>>
|
||||||
<%- preBodyTags %>
|
<%~ it.preBodyTags %>
|
||||||
<div id="__docusaurus">
|
<div id="__docusaurus">
|
||||||
<%- appHtml %>
|
<%~ it.appHtml %>
|
||||||
</div>
|
</div>
|
||||||
<% scripts.forEach((script) => { %>
|
<% it.scripts.forEach((script) => { %>
|
||||||
<script type="text/javascript" src="<%= baseUrl %><%= script %>"></script>
|
<script type="text/javascript" src="<%= it.baseUrl %><%= script %>"></script>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
<%- postBodyTags %>
|
<%~ it.postBodyTags %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -61,8 +61,6 @@ export function createBaseConfig(
|
||||||
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
|
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
|
||||||
symlinks: true,
|
symlinks: true,
|
||||||
alias: {
|
alias: {
|
||||||
// https://stackoverflow.com/a/55433680/6072730
|
|
||||||
ejs: 'ejs/ejs.min.js',
|
|
||||||
'@site': siteDir,
|
'@site': siteDir,
|
||||||
'@generated': generatedFilesDir,
|
'@generated': generatedFilesDir,
|
||||||
'@docusaurus': path.resolve(__dirname, '../client/exports'),
|
'@docusaurus': path.resolve(__dirname, '../client/exports'),
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -6194,11 +6194,6 @@ ejs@^2.6.1:
|
||||||
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba"
|
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba"
|
||||||
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
|
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:
|
electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.322:
|
||||||
version "1.3.322"
|
version "1.3.322"
|
||||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.322.tgz#a6f7e1c79025c2b05838e8e344f6e89eb83213a8"
|
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.322.tgz#a6f7e1c79025c2b05838e8e344f6e89eb83213a8"
|
||||||
|
@ -6700,6 +6695,11 @@ esutils@^2.0.2:
|
||||||
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
|
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
|
||||||
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
|
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:
|
etag@~1.8.1:
|
||||||
version "1.8.1"
|
version "1.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue