@docusaurus/core 0.0.0-6096 → 0.0.0-6098

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,13 +157,17 @@ async function executeSSG({ props, serverBundlePath, clientManifestPath, router,
157
157
  logger_1.PerfLogger.end('Generate Hash Router entry point');
158
158
  return { collectedData: {} };
159
159
  }
160
- const renderer = await logger_1.PerfLogger.async('Load App renderer', () => (0, ssg_1.loadAppRenderer)({
161
- serverBundlePath,
162
- }));
160
+ const [renderer, htmlMinifier] = await Promise.all([
161
+ logger_1.PerfLogger.async('Load App renderer', () => (0, ssg_1.loadAppRenderer)({
162
+ serverBundlePath,
163
+ })),
164
+ logger_1.PerfLogger.async('Load HTML minifier', () => (0, bundler_1.getHtmlMinifier)({ siteConfig: props.siteConfig })),
165
+ ]);
163
166
  const ssgResult = await logger_1.PerfLogger.async('Generate static files', () => (0, ssg_1.generateStaticFiles)({
164
167
  pathnames: props.routesPaths,
165
168
  renderer,
166
169
  params,
170
+ htmlMinifier,
167
171
  }));
168
172
  return ssgResult;
169
173
  }
@@ -25,6 +25,7 @@ exports.DEFAULT_STORAGE_CONFIG = {
25
25
  exports.DEFAULT_FASTER_CONFIG = {
26
26
  swcJsLoader: false,
27
27
  swcJsMinimizer: false,
28
+ swcHtmlMinimizer: false,
28
29
  lightningCssMinimizer: false,
29
30
  mdxCrossCompilerCache: false,
30
31
  rspackBundler: false,
@@ -33,6 +34,7 @@ exports.DEFAULT_FASTER_CONFIG = {
33
34
  exports.DEFAULT_FASTER_CONFIG_TRUE = {
34
35
  swcJsLoader: true,
35
36
  swcJsMinimizer: true,
37
+ swcHtmlMinimizer: true,
36
38
  lightningCssMinimizer: true,
37
39
  mdxCrossCompilerCache: true,
38
40
  rspackBundler: true,
@@ -150,6 +152,7 @@ const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
150
152
  .try(utils_validation_1.Joi.object({
151
153
  swcJsLoader: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsLoader),
152
154
  swcJsMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsMinimizer),
155
+ swcHtmlMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcHtmlMinimizer),
153
156
  lightningCssMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.lightningCssMinimizer),
154
157
  mdxCrossCompilerCache: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache),
155
158
  rspackBundler: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.rspackBundler),
package/lib/ssg.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { AppRenderer, SiteCollectedData } from './common';
8
+ import type { HtmlMinifier } from '@docusaurus/bundler';
8
9
  import type { Manifest } from 'react-loadable-ssr-addon-v5-slorber';
9
10
  import type { SSRTemplateCompiled } from './templates/templates';
10
11
  export type SSGParams = {
@@ -22,10 +23,11 @@ export type SSGParams = {
22
23
  export declare function loadAppRenderer({ serverBundlePath, }: {
23
24
  serverBundlePath: string;
24
25
  }): Promise<AppRenderer>;
25
- export declare function generateStaticFiles({ pathnames, renderer, params, }: {
26
+ export declare function generateStaticFiles({ pathnames, renderer, params, htmlMinifier, }: {
26
27
  pathnames: string[];
27
28
  renderer: AppRenderer;
28
29
  params: SSGParams;
30
+ htmlMinifier: HtmlMinifier;
29
31
  }): Promise<{
30
32
  collectedData: SiteCollectedData;
31
33
  }>;
package/lib/ssg.js CHANGED
@@ -16,7 +16,6 @@ const path_1 = tslib_1.__importDefault(require("path"));
16
16
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
17
17
  const eval_1 = tslib_1.__importDefault(require("eval"));
18
18
  const p_map_1 = tslib_1.__importDefault(require("p-map"));
19
- const html_minifier_terser_1 = require("html-minifier-terser");
20
19
  const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
21
20
  const templates_1 = require("./templates/templates");
22
21
  // Secret way to set SSR plugin concurrency option
@@ -67,13 +66,14 @@ function pathnameToFilename({ pathname, trailingSlash, }) {
67
66
  }
68
67
  return `${outputFileName}.html`;
69
68
  }
70
- async function generateStaticFiles({ pathnames, renderer, params, }) {
69
+ async function generateStaticFiles({ pathnames, renderer, params, htmlMinifier, }) {
71
70
  // Note that we catch all async errors on purpose
72
71
  // Docusaurus presents all the SSG errors to the user, not just the first one
73
72
  const results = await (0, p_map_1.default)(pathnames, async (pathname) => generateStaticFile({
74
73
  pathname,
75
74
  renderer,
76
75
  params,
76
+ htmlMinifier,
77
77
  }).then((result) => ({ pathname, result, error: null }), (error) => ({ pathname, result: null, error: error })), { concurrency: Concurrency });
78
78
  const [allSSGErrors, allSSGSuccesses] = lodash_1.default.partition(results, (r) => !!r.error);
79
79
  if (allSSGErrors.length > 0) {
@@ -92,7 +92,7 @@ async function generateStaticFiles({ pathnames, renderer, params, }) {
92
92
  .value();
93
93
  return { collectedData };
94
94
  }
95
- async function generateStaticFile({ pathname, renderer, params, }) {
95
+ async function generateStaticFile({ pathname, renderer, params, htmlMinifier, }) {
96
96
  try {
97
97
  // This only renders the app HTML
98
98
  const result = await renderer({
@@ -103,7 +103,7 @@ async function generateStaticFile({ pathname, renderer, params, }) {
103
103
  params,
104
104
  result,
105
105
  });
106
- const content = await minifyHtml(fullPageHtml);
106
+ const content = await htmlMinifier.minify(fullPageHtml);
107
107
  await writeStaticFile({
108
108
  pathname,
109
109
  content,
@@ -151,23 +151,3 @@ async function writeStaticFile({ content, pathname, params, }) {
151
151
  await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
152
152
  await fs_extra_1.default.writeFile(filePath, content);
153
153
  }
154
- async function minifyHtml(html) {
155
- try {
156
- if (process.env.SKIP_HTML_MINIFICATION === 'true') {
157
- return html;
158
- }
159
- // Minify html with https://github.com/DanielRuf/html-minifier-terser
160
- return await (0, html_minifier_terser_1.minify)(html, {
161
- removeComments: false,
162
- removeRedundantAttributes: true,
163
- removeEmptyAttributes: true,
164
- removeScriptTypeAttributes: true,
165
- removeStyleLinkTypeAttributes: true,
166
- useShortDoctype: true,
167
- minifyJS: true,
168
- });
169
- }
170
- catch (err) {
171
- throw new Error('HTML minification failed', { cause: err });
172
- }
173
- }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "0.0.0-6096",
4
+ "version": "0.0.0-6098",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -33,13 +33,13 @@
33
33
  "url": "https://github.com/facebook/docusaurus/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@docusaurus/babel": "0.0.0-6096",
37
- "@docusaurus/bundler": "0.0.0-6096",
38
- "@docusaurus/logger": "0.0.0-6096",
39
- "@docusaurus/mdx-loader": "0.0.0-6096",
40
- "@docusaurus/utils": "0.0.0-6096",
41
- "@docusaurus/utils-common": "0.0.0-6096",
42
- "@docusaurus/utils-validation": "0.0.0-6096",
36
+ "@docusaurus/babel": "0.0.0-6098",
37
+ "@docusaurus/bundler": "0.0.0-6098",
38
+ "@docusaurus/logger": "0.0.0-6098",
39
+ "@docusaurus/mdx-loader": "0.0.0-6098",
40
+ "@docusaurus/utils": "0.0.0-6098",
41
+ "@docusaurus/utils-common": "0.0.0-6098",
42
+ "@docusaurus/utils-validation": "0.0.0-6098",
43
43
  "boxen": "^6.2.1",
44
44
  "chalk": "^4.1.2",
45
45
  "chokidar": "^3.5.3",
@@ -53,9 +53,8 @@
53
53
  "eta": "^2.2.0",
54
54
  "eval": "^0.1.8",
55
55
  "fs-extra": "^11.1.1",
56
- "html-minifier-terser": "^7.2.0",
57
56
  "html-tags": "^3.3.1",
58
- "html-webpack-plugin": "^5.5.3",
57
+ "html-webpack-plugin": "^5.6.0",
59
58
  "leven": "^3.1.0",
60
59
  "lodash": "^4.17.21",
61
60
  "p-map": "^4.0.0",
@@ -79,8 +78,8 @@
79
78
  "webpack-merge": "^6.0.1"
80
79
  },
81
80
  "devDependencies": {
82
- "@docusaurus/module-type-aliases": "0.0.0-6096",
83
- "@docusaurus/types": "0.0.0-6096",
81
+ "@docusaurus/module-type-aliases": "0.0.0-6098",
82
+ "@docusaurus/types": "0.0.0-6098",
84
83
  "@total-typescript/shoehorn": "^0.1.2",
85
84
  "@types/detect-port": "^1.3.3",
86
85
  "@types/react-dom": "^18.2.7",
@@ -107,5 +106,5 @@
107
106
  "engines": {
108
107
  "node": ">=18.0"
109
108
  },
110
- "gitHead": "4005addf94d2f52e3908088601f036b5aff7acd7"
109
+ "gitHead": "d0a89b89c2ace47f7e76829fbf41681cde932bb9"
111
110
  }