@docusaurus/core 4.0.0-canary-6843 → 4.0.0-canary-6845
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.
- package/lib/client/exports/BrowserOnly.js +15 -13
- package/lib/webpack/client.js +11 -10
- package/lib/webpack/plugins/DevHtmlPlugin.d.ts +30 -0
- package/lib/webpack/plugins/DevHtmlPlugin.js +67 -0
- package/lib/webpack/templates/dev.html.template.d.ts +15 -0
- package/lib/webpack/templates/dev.html.template.js +31 -0
- package/package.json +13 -14
- package/lib/webpack/templates/dev.html.template.ejs +0 -16
|
@@ -4,19 +4,21 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, { isValidElement } from 'react';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
throw new Error(`Docusaurus error: The children of <BrowserOnly> must be a "render function", e.g. <BrowserOnly>{() => <span>{window.location.href}</span>}</BrowserOnly>.
|
|
7
|
+
import React, { Suspense, isValidElement, use } from 'react';
|
|
8
|
+
import { browser } from 'react-dom';
|
|
9
|
+
function BrowserOnlyContent({ children }) {
|
|
10
|
+
// On the server, this bails out to the closest Suspense boundary fallback
|
|
11
|
+
// On the client, this is a no-op
|
|
12
|
+
use(browser());
|
|
13
|
+
if (typeof children !== 'function' &&
|
|
14
|
+
process.env.NODE_ENV === 'development') {
|
|
15
|
+
throw new Error(`Docusaurus error: The children of <BrowserOnly> must be a "render function", e.g. <BrowserOnly>{() => <span>{window.location.href}</span>}</BrowserOnly>.
|
|
17
16
|
Current type: ${isValidElement(children) ? 'React element' : typeof children}`);
|
|
18
|
-
}
|
|
19
|
-
return <>{children?.()}</>;
|
|
20
17
|
}
|
|
21
|
-
return
|
|
18
|
+
return <>{children?.()}</>;
|
|
19
|
+
}
|
|
20
|
+
export default function BrowserOnly({ children, fallback }) {
|
|
21
|
+
return (<Suspense fallback={fallback ?? null}>
|
|
22
|
+
<BrowserOnlyContent>{children}</BrowserOnlyContent>
|
|
23
|
+
</Suspense>);
|
|
22
24
|
}
|
package/lib/webpack/client.js
CHANGED
|
@@ -13,13 +13,14 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
13
13
|
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
14
14
|
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
15
15
|
const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
|
|
16
|
-
const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
|
|
17
16
|
const bundler_1 = require("@docusaurus/bundler");
|
|
18
17
|
const utils_1 = require("@docusaurus/utils");
|
|
19
18
|
const base_1 = require("./base");
|
|
20
19
|
const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
|
|
21
20
|
const ForceTerminatePlugin_1 = tslib_1.__importDefault(require("./plugins/ForceTerminatePlugin"));
|
|
21
|
+
const DevHtmlPlugin_1 = tslib_1.__importDefault(require("./plugins/DevHtmlPlugin"));
|
|
22
22
|
const StaticDirectoriesCopyPlugin_1 = require("./plugins/StaticDirectoriesCopyPlugin");
|
|
23
|
+
const dev_html_template_1 = require("./templates/dev.html.template");
|
|
23
24
|
async function createBaseClientConfig({ props, hydrate, minify, faster, configureWebpackUtils, }) {
|
|
24
25
|
const baseConfig = await (0, base_1.createBaseConfig)({
|
|
25
26
|
props,
|
|
@@ -76,16 +77,16 @@ async function createStartClientConfig({ props, minify, poll, faster, configureW
|
|
|
76
77
|
},
|
|
77
78
|
plugins: [
|
|
78
79
|
// Generates an `index.html` file with the <script> injected.
|
|
79
|
-
new
|
|
80
|
-
template: path_1.default.join(__dirname, './templates/dev.html.template.ejs'),
|
|
81
|
-
// So we can define the position where the scripts are injected.
|
|
82
|
-
inject: false,
|
|
80
|
+
new DevHtmlPlugin_1.default({
|
|
83
81
|
filename: 'index.html',
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
render: (assets) => (0, dev_html_template_1.renderDevHtml)({
|
|
83
|
+
...assets,
|
|
84
|
+
title: siteConfig.title,
|
|
85
|
+
headTags,
|
|
86
|
+
preBodyTags,
|
|
87
|
+
postBodyTags,
|
|
88
|
+
lang: (0, utils_1.getLocaleConfig)(props.i18n).htmlLang,
|
|
89
|
+
}),
|
|
89
90
|
}),
|
|
90
91
|
],
|
|
91
92
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Compiler } from 'webpack';
|
|
8
|
+
export type DevHtmlAssets = {
|
|
9
|
+
scripts: string[];
|
|
10
|
+
stylesheets: string[];
|
|
11
|
+
};
|
|
12
|
+
export type DevHtmlPluginOptions = {
|
|
13
|
+
filename: string;
|
|
14
|
+
render: (assets: DevHtmlAssets) => string;
|
|
15
|
+
};
|
|
16
|
+
export declare function getAssetUrls({ files, publicPath, }: {
|
|
17
|
+
files: string[];
|
|
18
|
+
publicPath: string;
|
|
19
|
+
}): DevHtmlAssets;
|
|
20
|
+
/**
|
|
21
|
+
* Emits the HTML page used by "docusaurus start" to load the client bundle.
|
|
22
|
+
*
|
|
23
|
+
* Replaces html-webpack-plugin: we only need the entrypoint asset URLs,
|
|
24
|
+
* and this works the same way with Webpack and Rspack.
|
|
25
|
+
*/
|
|
26
|
+
export default class DevHtmlPlugin {
|
|
27
|
+
readonly options: DevHtmlPluginOptions;
|
|
28
|
+
constructor(options: DevHtmlPluginOptions);
|
|
29
|
+
apply(compiler: Compiler): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getAssetUrls = getAssetUrls;
|
|
10
|
+
const PluginName = 'Docusaurus-DevHtmlPlugin';
|
|
11
|
+
// Same as html-webpack-plugin: encode each path segment, keep the querystring
|
|
12
|
+
function encodeFilePath(filePath) {
|
|
13
|
+
const [urlPath, ...queryParts] = filePath.split('?');
|
|
14
|
+
const query = queryParts.length > 0 ? `?${queryParts.join('?')}` : '';
|
|
15
|
+
return urlPath.split('/').map(encodeURIComponent).join('/') + query;
|
|
16
|
+
}
|
|
17
|
+
// With "auto" (hash router), assets are resolved relatively to the page
|
|
18
|
+
// The generated HTML file is always emitted at the output root
|
|
19
|
+
function getPublicPath(publicPath) {
|
|
20
|
+
if (publicPath === 'auto') {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
return publicPath.endsWith('/') ? publicPath : `${publicPath}/`;
|
|
24
|
+
}
|
|
25
|
+
function getAssetUrls({ files, publicPath, }) {
|
|
26
|
+
const toUrls = (regexp) => [...new Set(files)]
|
|
27
|
+
.filter((file) => regexp.test(file))
|
|
28
|
+
.map((file) => getPublicPath(publicPath) + encodeFilePath(file));
|
|
29
|
+
return {
|
|
30
|
+
scripts: toUrls(/\.m?js(?:\?|$)/),
|
|
31
|
+
stylesheets: toUrls(/\.css(?:\?|$)/),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function getEntrypointAssets(compilation) {
|
|
35
|
+
const files = Array.from(compilation.entrypoints.values())
|
|
36
|
+
.flatMap((entrypoint) => entrypoint.getFiles())
|
|
37
|
+
.filter((file) => {
|
|
38
|
+
const info = compilation.getAsset(file)?.info;
|
|
39
|
+
return !info?.hotModuleReplacement && !info?.development;
|
|
40
|
+
});
|
|
41
|
+
const publicPath = compilation.getAssetPath(compilation.outputOptions.publicPath, { hash: compilation.hash });
|
|
42
|
+
return getAssetUrls({ files, publicPath });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Emits the HTML page used by "docusaurus start" to load the client bundle.
|
|
46
|
+
*
|
|
47
|
+
* Replaces html-webpack-plugin: we only need the entrypoint asset URLs,
|
|
48
|
+
* and this works the same way with Webpack and Rspack.
|
|
49
|
+
*/
|
|
50
|
+
class DevHtmlPlugin {
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.options = options;
|
|
53
|
+
}
|
|
54
|
+
apply(compiler) {
|
|
55
|
+
const { RawSource } = compiler.webpack.sources;
|
|
56
|
+
compiler.hooks.thisCompilation.tap(PluginName, (compilation) => {
|
|
57
|
+
compilation.hooks.processAssets.tap({
|
|
58
|
+
name: PluginName,
|
|
59
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
|
|
60
|
+
}, () => {
|
|
61
|
+
const html = this.options.render(getEntrypointAssets(compilation));
|
|
62
|
+
compilation.emitAsset(this.options.filename, new RawSource(html));
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = DevHtmlPlugin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { DevHtmlAssets } from '../plugins/DevHtmlPlugin';
|
|
8
|
+
export type DevHtmlTemplateParams = DevHtmlAssets & {
|
|
9
|
+
lang: string;
|
|
10
|
+
title: string;
|
|
11
|
+
headTags: string;
|
|
12
|
+
preBodyTags: string;
|
|
13
|
+
postBodyTags: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function renderDevHtml({ lang, title, headTags, preBodyTags, postBodyTags, scripts, stylesheets, }: DevHtmlTemplateParams): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.renderDevHtml = renderDevHtml;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
12
|
+
// HTML page served by "docusaurus start", the app is only rendered client-side
|
|
13
|
+
function renderDevHtml({ lang, title, headTags, preBodyTags, postBodyTags, scripts, stylesheets, }) {
|
|
14
|
+
return `<!DOCTYPE html>
|
|
15
|
+
<html lang="${(0, escape_html_1.default)(lang)}">
|
|
16
|
+
<head>
|
|
17
|
+
<meta charset="utf-8">
|
|
18
|
+
<meta name="generator" content="Docusaurus">
|
|
19
|
+
<title>${(0, escape_html_1.default)(title)}</title>
|
|
20
|
+
${headTags}
|
|
21
|
+
${scripts.map((src) => `<script defer src="${(0, escape_html_1.default)(src)}"></script>`).join('')}
|
|
22
|
+
${stylesheets.map((href) => `<link href="${(0, escape_html_1.default)(href)}" rel="stylesheet">`).join('')}
|
|
23
|
+
</head>
|
|
24
|
+
<body>
|
|
25
|
+
${preBodyTags}
|
|
26
|
+
<div id="__docusaurus"></div>
|
|
27
|
+
${postBodyTags}
|
|
28
|
+
</body>
|
|
29
|
+
</html>
|
|
30
|
+
`;
|
|
31
|
+
}
|
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": "4.0.0-canary-
|
|
4
|
+
"version": "4.0.0-canary-6845",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "4.0.0-canary-
|
|
37
|
-
"@docusaurus/bundler": "4.0.0-canary-
|
|
38
|
-
"@docusaurus/glob": "4.0.0-canary-
|
|
39
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
40
|
-
"@docusaurus/mdx-loader": "4.0.0-canary-
|
|
41
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
42
|
-
"@docusaurus/utils-common": "4.0.0-canary-
|
|
43
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
36
|
+
"@docusaurus/babel": "4.0.0-canary-6845",
|
|
37
|
+
"@docusaurus/bundler": "4.0.0-canary-6845",
|
|
38
|
+
"@docusaurus/glob": "4.0.0-canary-6845",
|
|
39
|
+
"@docusaurus/logger": "4.0.0-canary-6845",
|
|
40
|
+
"@docusaurus/mdx-loader": "4.0.0-canary-6845",
|
|
41
|
+
"@docusaurus/utils": "4.0.0-canary-6845",
|
|
42
|
+
"@docusaurus/utils-common": "4.0.0-canary-6845",
|
|
43
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6845",
|
|
44
44
|
"boxen": "^8.0.1",
|
|
45
45
|
"cli-table3": "^0.6.5",
|
|
46
46
|
"combine-promises": "^1.2.0",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"execa": "^10.0.1",
|
|
53
53
|
"fs-extra": "^11.4.0",
|
|
54
54
|
"html-tags": "^5.1.0",
|
|
55
|
-
"html-webpack-plugin": "^5.6.8",
|
|
56
55
|
"leven": "^3.1.0",
|
|
57
56
|
"lodash": "^4.18.1",
|
|
58
57
|
"open": "^11.0.2",
|
|
@@ -75,8 +74,8 @@
|
|
|
75
74
|
"webpack-merge": "^6.0.1"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
|
-
"@docusaurus/module-type-aliases": "4.0.0-canary-
|
|
79
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
77
|
+
"@docusaurus/module-type-aliases": "4.0.0-canary-6845",
|
|
78
|
+
"@docusaurus/types": "4.0.0-canary-6845",
|
|
80
79
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
81
80
|
"@types/escape-html": "^1.0.4",
|
|
82
81
|
"@types/history": "^4.7.11",
|
|
@@ -91,7 +90,7 @@
|
|
|
91
90
|
"utility-types": "^3.11.0"
|
|
92
91
|
},
|
|
93
92
|
"peerDependencies": {
|
|
94
|
-
"@docusaurus/faster": "4.0.0-canary-
|
|
93
|
+
"@docusaurus/faster": "4.0.0-canary-6845",
|
|
95
94
|
"@mdx-js/react": "^3.1.1",
|
|
96
95
|
"react": "^19.3.0",
|
|
97
96
|
"react-dom": "^19.3.0"
|
|
@@ -104,5 +103,5 @@
|
|
|
104
103
|
"engines": {
|
|
105
104
|
"node": ">=24.21"
|
|
106
105
|
},
|
|
107
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "102c713e834ec9ba5dda0ccc2e03665f8af350c0"
|
|
108
107
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="<%= htmlWebpackPlugin.options.lang %>">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="generator" content="Docusaurus">
|
|
6
|
-
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
7
|
-
<%= htmlWebpackPlugin.options.headTags %>
|
|
8
|
-
<%= htmlWebpackPlugin.tags.headTags %>
|
|
9
|
-
</head>
|
|
10
|
-
<body>
|
|
11
|
-
<%= htmlWebpackPlugin.options.preBodyTags %>
|
|
12
|
-
<div id="__docusaurus"></div>
|
|
13
|
-
<%= htmlWebpackPlugin.tags.bodyTags %>
|
|
14
|
-
<%= htmlWebpackPlugin.options.postBodyTags %>
|
|
15
|
-
</body>
|
|
16
|
-
</html>
|