@docusaurus/core 3.1.1 → 3.2.0
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/bin/docusaurus.mjs +10 -5
- package/lib/client/{serverRenderer.d.ts → renderToHtml.d.ts} +1 -1
- package/lib/client/{serverRenderer.js → renderToHtml.js} +1 -1
- package/lib/client/serverEntry.d.ts +3 -4
- package/lib/client/serverEntry.js +12 -113
- package/lib/client/theme-fallback/Error/index.js +22 -8
- package/lib/commands/build.d.ts +3 -3
- package/lib/commands/build.js +133 -112
- package/lib/commands/deploy.d.ts +2 -2
- package/lib/commands/deploy.js +3 -3
- package/lib/commands/external.js +2 -2
- package/lib/commands/serve.d.ts +2 -2
- package/lib/commands/serve.js +4 -4
- package/lib/commands/{start.d.ts → start/start.d.ts} +3 -3
- package/lib/commands/start/start.js +47 -0
- package/lib/commands/start/utils.d.ts +31 -0
- package/lib/commands/start/utils.js +87 -0
- package/lib/commands/start/watcher.d.ts +42 -0
- package/lib/commands/start/watcher.js +78 -0
- package/lib/commands/start/webpack.d.ts +15 -0
- package/lib/commands/start/webpack.js +133 -0
- package/lib/commands/swizzle/common.d.ts +1 -0
- package/lib/commands/swizzle/common.js +1 -0
- package/lib/commands/swizzle/context.js +2 -2
- package/lib/commands/swizzle/index.js +32 -3
- package/lib/commands/writeHeadingIds.js +2 -2
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +3 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/server/brokenLinks.js +4 -4
- package/lib/server/clientModules.d.ts +1 -1
- package/lib/server/clientModules.js +3 -3
- package/lib/server/codegen/codegen.d.ts +20 -0
- package/lib/server/codegen/codegen.js +65 -0
- package/lib/server/codegen/codegenRoutes.d.ts +49 -0
- package/lib/server/codegen/codegenRoutes.js +190 -0
- package/lib/server/configValidation.js +6 -4
- package/lib/server/i18n.d.ts +2 -2
- package/lib/server/i18n.js +20 -2
- package/lib/server/plugins/actions.d.ts +19 -0
- package/lib/server/plugins/actions.js +62 -0
- package/lib/server/plugins/init.js +3 -3
- package/lib/server/plugins/plugins.d.ts +21 -0
- package/lib/server/plugins/plugins.js +188 -0
- package/lib/server/plugins/pluginsUtils.d.ts +16 -0
- package/lib/server/plugins/pluginsUtils.js +75 -0
- package/lib/server/plugins/routeConfig.d.ts +1 -1
- package/lib/server/plugins/routeConfig.js +4 -4
- package/lib/server/plugins/synthetic.d.ts +3 -3
- package/lib/server/plugins/synthetic.js +0 -2
- package/lib/server/routes.d.ts +3 -45
- package/lib/server/routes.js +16 -168
- package/lib/server/{index.d.ts → site.d.ts} +12 -5
- package/lib/server/site.js +164 -0
- package/lib/server/siteMetadata.d.ts +5 -4
- package/lib/server/siteMetadata.js +14 -10
- package/lib/server/translations/translations.d.ts +9 -2
- package/lib/server/translations/translations.js +21 -4
- package/lib/server/utils.d.ts +0 -2
- package/lib/server/utils.js +1 -9
- package/lib/ssg.d.ts +31 -0
- package/lib/ssg.js +167 -0
- package/lib/templates/templates.d.ts +28 -0
- package/lib/templates/templates.js +63 -0
- package/lib/utils.d.ts +9 -0
- package/lib/utils.js +78 -0
- package/lib/webpack/base.d.ts +5 -1
- package/lib/webpack/base.js +4 -6
- package/lib/webpack/client.d.ts +15 -1
- package/lib/webpack/client.js +78 -23
- package/lib/webpack/minification.d.ts +8 -0
- package/lib/webpack/minification.js +97 -0
- package/lib/webpack/server.d.ts +5 -3
- package/lib/webpack/server.js +41 -50
- package/lib/webpack/utils.d.ts +13 -4
- package/lib/webpack/utils.js +27 -83
- package/package.json +13 -11
- package/lib/commands/start.js +0 -212
- package/lib/server/index.js +0 -154
- package/lib/server/plugins/index.d.ts +0 -18
- package/lib/server/plugins/index.js +0 -106
- /package/lib/{webpack/templates/index.html.template.ejs → templates/dev.html.template.ejs} +0 -0
- /package/lib/{webpack/templates → templates}/ssr.html.template.d.ts +0 -0
- /package/lib/{webpack/templates → templates}/ssr.html.template.js +0 -0
package/lib/webpack/utils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.getHttpsConfig = exports.compile = exports.executePluginsConfigureWebpack = exports.executePluginsConfigurePostCss = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = exports.printStatsWarnings = exports.formatStatsErrorMessage = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -16,8 +16,6 @@ const utils_1 = require("@docusaurus/utils");
|
|
|
16
16
|
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
17
17
|
const webpack_merge_1 = require("webpack-merge");
|
|
18
18
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
19
|
-
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
20
|
-
const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
|
|
21
19
|
const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
|
|
22
20
|
function formatStatsErrorMessage(statsJson) {
|
|
23
21
|
if (statsJson?.errors?.length) {
|
|
@@ -189,6 +187,31 @@ function applyConfigurePostCss(configurePostCss, config) {
|
|
|
189
187
|
return config;
|
|
190
188
|
}
|
|
191
189
|
exports.applyConfigurePostCss = applyConfigurePostCss;
|
|
190
|
+
// Plugin Lifecycle - configurePostCss()
|
|
191
|
+
function executePluginsConfigurePostCss({ plugins, config, }) {
|
|
192
|
+
let resultConfig = config;
|
|
193
|
+
plugins.forEach((plugin) => {
|
|
194
|
+
const { configurePostCss } = plugin;
|
|
195
|
+
if (configurePostCss) {
|
|
196
|
+
resultConfig = applyConfigurePostCss(configurePostCss.bind(plugin), resultConfig);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return resultConfig;
|
|
200
|
+
}
|
|
201
|
+
exports.executePluginsConfigurePostCss = executePluginsConfigurePostCss;
|
|
202
|
+
// Plugin Lifecycle - configureWebpack()
|
|
203
|
+
function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }) {
|
|
204
|
+
let resultConfig = config;
|
|
205
|
+
plugins.forEach((plugin) => {
|
|
206
|
+
const { configureWebpack } = plugin;
|
|
207
|
+
if (configureWebpack) {
|
|
208
|
+
resultConfig = applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
209
|
+
resultConfig, isServer, jsLoader, plugin.content);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return resultConfig;
|
|
213
|
+
}
|
|
214
|
+
exports.executePluginsConfigureWebpack = executePluginsConfigureWebpack;
|
|
192
215
|
function compile(config) {
|
|
193
216
|
return new Promise((resolve, reject) => {
|
|
194
217
|
const compiler = (0, webpack_1.default)(config);
|
|
@@ -215,7 +238,7 @@ function compile(config) {
|
|
|
215
238
|
reject(errClose);
|
|
216
239
|
}
|
|
217
240
|
else {
|
|
218
|
-
resolve();
|
|
241
|
+
resolve(stats);
|
|
219
242
|
}
|
|
220
243
|
});
|
|
221
244
|
});
|
|
@@ -269,82 +292,3 @@ async function getHttpsConfig() {
|
|
|
269
292
|
return isHttps;
|
|
270
293
|
}
|
|
271
294
|
exports.getHttpsConfig = getHttpsConfig;
|
|
272
|
-
// See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
|
|
273
|
-
function getTerserParallel() {
|
|
274
|
-
let terserParallel = true;
|
|
275
|
-
if (process.env.TERSER_PARALLEL === 'false') {
|
|
276
|
-
terserParallel = false;
|
|
277
|
-
}
|
|
278
|
-
else if (process.env.TERSER_PARALLEL &&
|
|
279
|
-
parseInt(process.env.TERSER_PARALLEL, 10) > 0) {
|
|
280
|
-
terserParallel = parseInt(process.env.TERSER_PARALLEL, 10);
|
|
281
|
-
}
|
|
282
|
-
return terserParallel;
|
|
283
|
-
}
|
|
284
|
-
function getMinimizer(useSimpleCssMinifier = false) {
|
|
285
|
-
const minimizer = [
|
|
286
|
-
new terser_webpack_plugin_1.default({
|
|
287
|
-
parallel: getTerserParallel(),
|
|
288
|
-
terserOptions: {
|
|
289
|
-
parse: {
|
|
290
|
-
// We want uglify-js to parse ecma 8 code. However, we don't want it
|
|
291
|
-
// to apply any minification steps that turns valid ecma 5 code
|
|
292
|
-
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
293
|
-
// sections only apply transformations that are ecma 5 safe
|
|
294
|
-
// https://github.com/facebook/create-react-app/pull/4234
|
|
295
|
-
ecma: 2020,
|
|
296
|
-
},
|
|
297
|
-
compress: {
|
|
298
|
-
ecma: 5,
|
|
299
|
-
},
|
|
300
|
-
mangle: {
|
|
301
|
-
safari10: true,
|
|
302
|
-
},
|
|
303
|
-
output: {
|
|
304
|
-
ecma: 5,
|
|
305
|
-
comments: false,
|
|
306
|
-
// Turned on because emoji and regex is not minified properly using
|
|
307
|
-
// default. See https://github.com/facebook/create-react-app/issues/2488
|
|
308
|
-
ascii_only: true,
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
}),
|
|
312
|
-
];
|
|
313
|
-
if (useSimpleCssMinifier) {
|
|
314
|
-
minimizer.push(new css_minimizer_webpack_plugin_1.default());
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
minimizer.push(
|
|
318
|
-
// Using the array syntax to add 2 minimizers
|
|
319
|
-
// see https://github.com/webpack-contrib/css-minimizer-webpack-plugin#array
|
|
320
|
-
new css_minimizer_webpack_plugin_1.default({
|
|
321
|
-
minimizerOptions: [
|
|
322
|
-
// CssNano options
|
|
323
|
-
{
|
|
324
|
-
preset: require.resolve('@docusaurus/cssnano-preset'),
|
|
325
|
-
},
|
|
326
|
-
// CleanCss options
|
|
327
|
-
{
|
|
328
|
-
inline: false,
|
|
329
|
-
level: {
|
|
330
|
-
1: {
|
|
331
|
-
all: false,
|
|
332
|
-
removeWhitespace: true,
|
|
333
|
-
},
|
|
334
|
-
2: {
|
|
335
|
-
all: true,
|
|
336
|
-
restructureRules: true,
|
|
337
|
-
removeUnusedAtRules: false,
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
},
|
|
341
|
-
],
|
|
342
|
-
minify: [
|
|
343
|
-
css_minimizer_webpack_plugin_1.default.cssnanoMinify,
|
|
344
|
-
css_minimizer_webpack_plugin_1.default.cleanCssMinify,
|
|
345
|
-
],
|
|
346
|
-
}));
|
|
347
|
-
}
|
|
348
|
-
return minimizer;
|
|
349
|
-
}
|
|
350
|
-
exports.getMinimizer = getMinimizer;
|
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": "3.
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -43,14 +43,13 @@
|
|
|
43
43
|
"@babel/runtime": "^7.22.6",
|
|
44
44
|
"@babel/runtime-corejs3": "^7.22.6",
|
|
45
45
|
"@babel/traverse": "^7.22.8",
|
|
46
|
-
"@docusaurus/cssnano-preset": "3.
|
|
47
|
-
"@docusaurus/logger": "3.
|
|
48
|
-
"@docusaurus/mdx-loader": "3.
|
|
46
|
+
"@docusaurus/cssnano-preset": "3.2.0",
|
|
47
|
+
"@docusaurus/logger": "3.2.0",
|
|
48
|
+
"@docusaurus/mdx-loader": "3.2.0",
|
|
49
49
|
"@docusaurus/react-loadable": "5.5.2",
|
|
50
|
-
"@docusaurus/utils": "3.
|
|
51
|
-
"@docusaurus/utils-common": "3.
|
|
52
|
-
"@docusaurus/utils-validation": "3.
|
|
53
|
-
"@slorber/static-site-generator-webpack-plugin": "^4.0.7",
|
|
50
|
+
"@docusaurus/utils": "3.2.0",
|
|
51
|
+
"@docusaurus/utils-common": "3.2.0",
|
|
52
|
+
"@docusaurus/utils-validation": "3.2.0",
|
|
54
53
|
"@svgr/webpack": "^6.5.1",
|
|
55
54
|
"autoprefixer": "^10.4.14",
|
|
56
55
|
"babel-loader": "^9.1.3",
|
|
@@ -71,6 +70,7 @@
|
|
|
71
70
|
"detect-port": "^1.5.1",
|
|
72
71
|
"escape-html": "^1.0.3",
|
|
73
72
|
"eta": "^2.2.0",
|
|
73
|
+
"eval": "^0.1.8",
|
|
74
74
|
"file-loader": "^6.2.0",
|
|
75
75
|
"fs-extra": "^11.1.1",
|
|
76
76
|
"html-minifier-terser": "^7.2.0",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"leven": "^3.1.0",
|
|
80
80
|
"lodash": "^4.17.21",
|
|
81
81
|
"mini-css-extract-plugin": "^2.7.6",
|
|
82
|
+
"p-map": "^4.0.0",
|
|
82
83
|
"postcss": "^8.4.26",
|
|
83
84
|
"postcss-loader": "^7.3.3",
|
|
84
85
|
"prompts": "^2.4.2",
|
|
@@ -104,8 +105,9 @@
|
|
|
104
105
|
"webpackbar": "^5.0.2"
|
|
105
106
|
},
|
|
106
107
|
"devDependencies": {
|
|
107
|
-
"@docusaurus/module-type-aliases": "3.
|
|
108
|
-
"@docusaurus/types": "3.
|
|
108
|
+
"@docusaurus/module-type-aliases": "3.2.0",
|
|
109
|
+
"@docusaurus/types": "3.2.0",
|
|
110
|
+
"@total-typescript/shoehorn": "^0.1.2",
|
|
109
111
|
"@types/detect-port": "^1.3.3",
|
|
110
112
|
"@types/react-dom": "^18.2.7",
|
|
111
113
|
"@types/react-router-config": "^5.0.7",
|
|
@@ -124,5 +126,5 @@
|
|
|
124
126
|
"engines": {
|
|
125
127
|
"node": ">=18.0"
|
|
126
128
|
},
|
|
127
|
-
"gitHead": "
|
|
129
|
+
"gitHead": "5af143651b26b39761361acd96e9c5be7ba0cb25"
|
|
128
130
|
}
|
package/lib/commands/start.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
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.start = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
-
const utils_1 = require("@docusaurus/utils");
|
|
16
|
-
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
17
|
-
const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
|
|
18
|
-
const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
|
|
19
|
-
const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
|
|
20
|
-
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
|
|
21
|
-
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
22
|
-
const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
|
|
23
|
-
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
24
|
-
const server_1 = require("../server");
|
|
25
|
-
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
26
|
-
const utils_2 = require("../webpack/utils");
|
|
27
|
-
const getHostPort_1 = require("../server/getHostPort");
|
|
28
|
-
async function start(siteDirParam = '.', cliOptions = {}) {
|
|
29
|
-
// Temporary workaround to unlock the ability to translate the site config
|
|
30
|
-
// We'll remove it if a better official API can be designed
|
|
31
|
-
// See https://github.com/facebook/docusaurus/issues/4542
|
|
32
|
-
process.env.DOCUSAURUS_CURRENT_LOCALE = cliOptions.locale;
|
|
33
|
-
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
34
|
-
logger_1.default.info('Starting the development server...');
|
|
35
|
-
function loadSite() {
|
|
36
|
-
return (0, server_1.load)({
|
|
37
|
-
siteDir,
|
|
38
|
-
config: cliOptions.config,
|
|
39
|
-
locale: cliOptions.locale,
|
|
40
|
-
localizePath: undefined, // Should this be configurable?
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// Process all related files as a prop.
|
|
44
|
-
const props = await loadSite();
|
|
45
|
-
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
46
|
-
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
47
|
-
if (port === null) {
|
|
48
|
-
process.exit();
|
|
49
|
-
}
|
|
50
|
-
const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
|
|
51
|
-
const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
|
|
52
|
-
const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
|
|
53
|
-
logger_1.default.success `Docusaurus website is running at: url=${openUrl}`;
|
|
54
|
-
// Reload files processing.
|
|
55
|
-
const reload = lodash_1.default.debounce(() => {
|
|
56
|
-
loadSite()
|
|
57
|
-
.then(({ baseUrl: newBaseUrl }) => {
|
|
58
|
-
const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
|
|
59
|
-
if (newOpenUrl !== openUrl) {
|
|
60
|
-
logger_1.default.success `Docusaurus website is running at: url=${newOpenUrl}`;
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
.catch((err) => {
|
|
64
|
-
logger_1.default.error(err.stack);
|
|
65
|
-
});
|
|
66
|
-
}, 500);
|
|
67
|
-
const { siteConfig, plugins, localizationDir } = props;
|
|
68
|
-
const normalizeToSiteDir = (filepath) => {
|
|
69
|
-
if (filepath && path_1.default.isAbsolute(filepath)) {
|
|
70
|
-
return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
|
|
71
|
-
}
|
|
72
|
-
return (0, utils_1.posixPath)(filepath);
|
|
73
|
-
};
|
|
74
|
-
const pluginPaths = plugins
|
|
75
|
-
.flatMap((plugin) => plugin.getPathsToWatch?.() ?? [])
|
|
76
|
-
.filter(Boolean)
|
|
77
|
-
.map(normalizeToSiteDir);
|
|
78
|
-
const pathsToWatch = [...pluginPaths, props.siteConfigPath, localizationDir];
|
|
79
|
-
const pollingOptions = {
|
|
80
|
-
usePolling: !!cliOptions.poll,
|
|
81
|
-
interval: Number.isInteger(cliOptions.poll)
|
|
82
|
-
? cliOptions.poll
|
|
83
|
-
: undefined,
|
|
84
|
-
};
|
|
85
|
-
const httpsConfig = await (0, utils_2.getHttpsConfig)();
|
|
86
|
-
const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
|
|
87
|
-
cwd: siteDir,
|
|
88
|
-
ignoreInitial: true,
|
|
89
|
-
...{ pollingOptions },
|
|
90
|
-
});
|
|
91
|
-
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload));
|
|
92
|
-
let config = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify, false), {
|
|
93
|
-
watchOptions: {
|
|
94
|
-
ignored: /node_modules\/(?!@docusaurus)/,
|
|
95
|
-
poll: cliOptions.poll,
|
|
96
|
-
},
|
|
97
|
-
infrastructureLogging: {
|
|
98
|
-
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
99
|
-
level: 'warn',
|
|
100
|
-
},
|
|
101
|
-
plugins: [
|
|
102
|
-
// Generates an `index.html` file with the <script> injected.
|
|
103
|
-
new html_webpack_plugin_1.default({
|
|
104
|
-
template: path_1.default.join(__dirname, '../webpack/templates/index.html.template.ejs'),
|
|
105
|
-
// So we can define the position where the scripts are injected.
|
|
106
|
-
inject: false,
|
|
107
|
-
filename: 'index.html',
|
|
108
|
-
title: siteConfig.title,
|
|
109
|
-
headTags,
|
|
110
|
-
preBodyTags,
|
|
111
|
-
postBodyTags,
|
|
112
|
-
}),
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
// Plugin Lifecycle - configureWebpack and configurePostCss.
|
|
116
|
-
plugins.forEach((plugin) => {
|
|
117
|
-
const { configureWebpack, configurePostCss } = plugin;
|
|
118
|
-
if (configurePostCss) {
|
|
119
|
-
config = (0, utils_2.applyConfigurePostCss)(configurePostCss.bind(plugin), config);
|
|
120
|
-
}
|
|
121
|
-
if (configureWebpack) {
|
|
122
|
-
config = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
123
|
-
config, false, props.siteConfig.webpack?.jsLoader, plugin.content);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
const compiler = (0, webpack_1.default)(config);
|
|
127
|
-
compiler.hooks.done.tap('done', (stats) => {
|
|
128
|
-
const errorsWarnings = stats.toJson('errors-warnings');
|
|
129
|
-
const statsErrorMessage = (0, utils_2.formatStatsErrorMessage)(errorsWarnings);
|
|
130
|
-
if (statsErrorMessage) {
|
|
131
|
-
console.error(statsErrorMessage);
|
|
132
|
-
}
|
|
133
|
-
(0, utils_2.printStatsWarnings)(errorsWarnings);
|
|
134
|
-
if (process.env.E2E_TEST) {
|
|
135
|
-
if (stats.hasErrors()) {
|
|
136
|
-
logger_1.default.error('E2E_TEST: Project has compiler errors.');
|
|
137
|
-
process.exit(1);
|
|
138
|
-
}
|
|
139
|
-
logger_1.default.success('E2E_TEST: Project can compile.');
|
|
140
|
-
process.exit(0);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
// https://webpack.js.org/configuration/dev-server
|
|
144
|
-
const defaultDevServerConfig = {
|
|
145
|
-
hot: cliOptions.hotOnly ? 'only' : true,
|
|
146
|
-
liveReload: false,
|
|
147
|
-
client: {
|
|
148
|
-
progress: true,
|
|
149
|
-
overlay: {
|
|
150
|
-
warnings: false,
|
|
151
|
-
errors: true,
|
|
152
|
-
},
|
|
153
|
-
webSocketURL: {
|
|
154
|
-
hostname: '0.0.0.0',
|
|
155
|
-
port: 0,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
headers: {
|
|
159
|
-
'access-control-allow-origin': '*',
|
|
160
|
-
},
|
|
161
|
-
devMiddleware: {
|
|
162
|
-
publicPath: baseUrl,
|
|
163
|
-
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
164
|
-
stats: 'summary',
|
|
165
|
-
},
|
|
166
|
-
static: siteConfig.staticDirectories.map((dir) => ({
|
|
167
|
-
publicPath: baseUrl,
|
|
168
|
-
directory: path_1.default.resolve(siteDir, dir),
|
|
169
|
-
watch: {
|
|
170
|
-
// Useful options for our own monorepo using symlinks!
|
|
171
|
-
// See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
|
|
172
|
-
followSymlinks: true,
|
|
173
|
-
ignored: /node_modules\/(?!@docusaurus)/,
|
|
174
|
-
...{ pollingOptions },
|
|
175
|
-
},
|
|
176
|
-
})),
|
|
177
|
-
...(httpsConfig && {
|
|
178
|
-
server: typeof httpsConfig === 'object'
|
|
179
|
-
? {
|
|
180
|
-
type: 'https',
|
|
181
|
-
options: httpsConfig,
|
|
182
|
-
}
|
|
183
|
-
: 'https',
|
|
184
|
-
}),
|
|
185
|
-
historyApiFallback: {
|
|
186
|
-
rewrites: [{ from: /\/*/, to: baseUrl }],
|
|
187
|
-
},
|
|
188
|
-
allowedHosts: 'all',
|
|
189
|
-
host,
|
|
190
|
-
port,
|
|
191
|
-
setupMiddlewares: (middlewares, devServer) => {
|
|
192
|
-
// This lets us fetch source contents from webpack for the error overlay.
|
|
193
|
-
middlewares.unshift((0, evalSourceMapMiddleware_1.default)(devServer));
|
|
194
|
-
return middlewares;
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
// Allow plugin authors to customize/override devServer config
|
|
198
|
-
const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
|
|
199
|
-
const devServer = new webpack_dev_server_1.default(devServerConfig, compiler);
|
|
200
|
-
devServer.startCallback(() => {
|
|
201
|
-
if (cliOptions.open) {
|
|
202
|
-
(0, openBrowser_1.default)(openUrl);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
206
|
-
process.on(sig, () => {
|
|
207
|
-
devServer.stop();
|
|
208
|
-
process.exit();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
exports.start = start;
|
package/lib/server/index.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
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.load = exports.loadContext = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
-
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const config_1 = require("./config");
|
|
15
|
-
const clientModules_1 = require("./clientModules");
|
|
16
|
-
const plugins_1 = require("./plugins");
|
|
17
|
-
const routes_1 = require("./routes");
|
|
18
|
-
const htmlTags_1 = require("./htmlTags");
|
|
19
|
-
const siteMetadata_1 = require("./siteMetadata");
|
|
20
|
-
const i18n_1 = require("./i18n");
|
|
21
|
-
const translations_1 = require("./translations/translations");
|
|
22
|
-
/**
|
|
23
|
-
* Loading context is the very first step in site building. Its options are
|
|
24
|
-
* directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
|
|
25
|
-
* context (which includes code translations). The `LoadContext` will be passed
|
|
26
|
-
* to plugin constructors.
|
|
27
|
-
*/
|
|
28
|
-
async function loadContext(options) {
|
|
29
|
-
const { siteDir, outDir: baseOutDir = utils_1.DEFAULT_BUILD_DIR_NAME, locale, config: customConfigFilePath, } = options;
|
|
30
|
-
const generatedFilesDir = path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
|
|
31
|
-
const { siteConfig: initialSiteConfig, siteConfigPath } = await (0, config_1.loadSiteConfig)({
|
|
32
|
-
siteDir,
|
|
33
|
-
customConfigFilePath,
|
|
34
|
-
});
|
|
35
|
-
const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
|
|
36
|
-
const baseUrl = (0, utils_1.localizePath)({
|
|
37
|
-
path: initialSiteConfig.baseUrl,
|
|
38
|
-
i18n,
|
|
39
|
-
options,
|
|
40
|
-
pathType: 'url',
|
|
41
|
-
});
|
|
42
|
-
const outDir = (0, utils_1.localizePath)({
|
|
43
|
-
path: path_1.default.resolve(siteDir, baseOutDir),
|
|
44
|
-
i18n,
|
|
45
|
-
options,
|
|
46
|
-
pathType: 'fs',
|
|
47
|
-
});
|
|
48
|
-
const siteConfig = { ...initialSiteConfig, baseUrl };
|
|
49
|
-
const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[i18n.currentLocale].path);
|
|
50
|
-
const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({ localizationDir })) ?? {};
|
|
51
|
-
// We only need key->message for code translations
|
|
52
|
-
const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
53
|
-
return {
|
|
54
|
-
siteDir,
|
|
55
|
-
generatedFilesDir,
|
|
56
|
-
localizationDir,
|
|
57
|
-
siteConfig,
|
|
58
|
-
siteConfigPath,
|
|
59
|
-
outDir,
|
|
60
|
-
baseUrl,
|
|
61
|
-
i18n,
|
|
62
|
-
codeTranslations,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.loadContext = loadContext;
|
|
66
|
-
/**
|
|
67
|
-
* This is the crux of the Docusaurus server-side. It reads everything it needs—
|
|
68
|
-
* code translations, config file, plugin modules... Plugins then use their
|
|
69
|
-
* lifecycles to generate content and other data. It is side-effect-ful because
|
|
70
|
-
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
71
|
-
*/
|
|
72
|
-
async function load(options) {
|
|
73
|
-
const { siteDir } = options;
|
|
74
|
-
const context = await loadContext(options);
|
|
75
|
-
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
|
|
76
|
-
const { plugins, pluginsRouteConfigs, globalData } = await (0, plugins_1.loadPlugins)(context);
|
|
77
|
-
const clientModules = (0, clientModules_1.loadClientModules)(plugins);
|
|
78
|
-
const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
|
|
79
|
-
const { registry, routesChunkNames, routesConfig, routesPaths } = (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl, siteConfig.onDuplicateRoutes);
|
|
80
|
-
const codeTranslations = {
|
|
81
|
-
...(await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins)),
|
|
82
|
-
...siteCodeTranslations,
|
|
83
|
-
};
|
|
84
|
-
const siteMetadata = await (0, siteMetadata_1.loadSiteMetadata)({ plugins, siteDir });
|
|
85
|
-
// === Side-effects part ===
|
|
86
|
-
const genWarning = (0, utils_1.generate)(generatedFilesDir,
|
|
87
|
-
// cSpell:ignore DONT
|
|
88
|
-
'DONT-EDIT-THIS-FOLDER', `This folder stores temp files that Docusaurus' client bundler accesses.
|
|
89
|
-
|
|
90
|
-
DO NOT hand-modify files in this folder because they will be overwritten in the
|
|
91
|
-
next build. You can clear all build artifacts (including this folder) with the
|
|
92
|
-
\`docusaurus clear\` command.
|
|
93
|
-
`);
|
|
94
|
-
const genSiteConfig = (0, utils_1.generate)(generatedFilesDir, `${utils_1.DEFAULT_CONFIG_FILE_NAME}.mjs`, `/*
|
|
95
|
-
* AUTOGENERATED - DON'T EDIT
|
|
96
|
-
* Your edits in this file will be overwritten in the next build!
|
|
97
|
-
* Modify the docusaurus.config.js file at your site's root instead.
|
|
98
|
-
*/
|
|
99
|
-
export default ${JSON.stringify(siteConfig, null, 2)};
|
|
100
|
-
`);
|
|
101
|
-
const genClientModules = (0, utils_1.generate)(generatedFilesDir, 'client-modules.js', `export default [
|
|
102
|
-
${clientModules
|
|
103
|
-
// Use `require()` because `import()` is async but client modules can have CSS
|
|
104
|
-
// and the order matters for loading CSS.
|
|
105
|
-
.map((clientModule) => ` require("${(0, utils_1.escapePath)(clientModule)}"),`)
|
|
106
|
-
.join('\n')}
|
|
107
|
-
];
|
|
108
|
-
`);
|
|
109
|
-
const genRegistry = (0, utils_1.generate)(generatedFilesDir, 'registry.js', `export default {
|
|
110
|
-
${Object.entries(registry)
|
|
111
|
-
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
112
|
-
.map(([chunkName, modulePath]) =>
|
|
113
|
-
// modulePath is already escaped by escapePath
|
|
114
|
-
` "${chunkName}": [() => import(/* webpackChunkName: "${chunkName}" */ "${modulePath}"), "${modulePath}", require.resolveWeak("${modulePath}")],`)
|
|
115
|
-
.join('\n')}};
|
|
116
|
-
`);
|
|
117
|
-
const genRoutesChunkNames = (0, utils_1.generate)(generatedFilesDir, 'routesChunkNames.json', JSON.stringify(routesChunkNames, null, 2));
|
|
118
|
-
const genRoutes = (0, utils_1.generate)(generatedFilesDir, 'routes.js', routesConfig);
|
|
119
|
-
const genGlobalData = (0, utils_1.generate)(generatedFilesDir, 'globalData.json', JSON.stringify(globalData, null, 2));
|
|
120
|
-
const genI18n = (0, utils_1.generate)(generatedFilesDir, 'i18n.json', JSON.stringify(i18n, null, 2));
|
|
121
|
-
const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslations, null, 2));
|
|
122
|
-
const genSiteMetadata = (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
|
|
123
|
-
await Promise.all([
|
|
124
|
-
genWarning,
|
|
125
|
-
genClientModules,
|
|
126
|
-
genSiteConfig,
|
|
127
|
-
genRegistry,
|
|
128
|
-
genRoutesChunkNames,
|
|
129
|
-
genRoutes,
|
|
130
|
-
genGlobalData,
|
|
131
|
-
genSiteMetadata,
|
|
132
|
-
genI18n,
|
|
133
|
-
genCodeTranslations,
|
|
134
|
-
]);
|
|
135
|
-
return {
|
|
136
|
-
siteConfig,
|
|
137
|
-
siteConfigPath,
|
|
138
|
-
siteMetadata,
|
|
139
|
-
siteDir,
|
|
140
|
-
outDir,
|
|
141
|
-
baseUrl,
|
|
142
|
-
i18n,
|
|
143
|
-
localizationDir,
|
|
144
|
-
generatedFilesDir,
|
|
145
|
-
routes: pluginsRouteConfigs,
|
|
146
|
-
routesPaths,
|
|
147
|
-
plugins,
|
|
148
|
-
headTags,
|
|
149
|
-
preBodyTags,
|
|
150
|
-
postBodyTags,
|
|
151
|
-
codeTranslations,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
exports.load = load;
|
|
@@ -1,18 +0,0 @@
|
|
|
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 { LoadContext, RouteConfig, GlobalData, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the plugins, runs `loadContent`, `translateContent`,
|
|
10
|
-
* `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
|
|
11
|
-
* side-effect-ful (it generates temp files), so is this function. This function
|
|
12
|
-
* would also mutate `context.siteConfig.themeConfig` to translate it.
|
|
13
|
-
*/
|
|
14
|
-
export declare function loadPlugins(context: LoadContext): Promise<{
|
|
15
|
-
plugins: LoadedPlugin[];
|
|
16
|
-
pluginsRouteConfigs: RouteConfig[];
|
|
17
|
-
globalData: GlobalData;
|
|
18
|
-
}>;
|