@docusaurus/core 2.0.0-beta.2 → 2.0.0-beta.22
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/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/docusaurus.mjs +221 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -8
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +40 -40
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +6 -13
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +108 -146
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +104 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +109 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +101 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +118 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +46 -25
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +4 -4
- package/lib/server/configValidation.js +86 -41
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +83 -165
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +73 -134
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +5 -1
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +45 -57
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +22 -9
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +15 -31
- package/lib/webpack/utils.js +61 -182
- package/package.json +81 -77
- package/bin/docusaurus.js +0 -325
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -40
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -8
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -40
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
package/lib/webpack/server.js
CHANGED
|
@@ -9,15 +9,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
11
|
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
// Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
|
|
14
|
+
const static_site_generator_webpack_plugin_1 = tslib_1.__importDefault(require("@slorber/static-site-generator-webpack-plugin"));
|
|
12
15
|
const base_1 = require("./base");
|
|
13
16
|
const WaitPlugin_1 = tslib_1.__importDefault(require("./plugins/WaitPlugin"));
|
|
14
17
|
const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
|
|
20
|
-
const config = base_1.createBaseConfig(props, true);
|
|
18
|
+
const ssr_html_template_1 = tslib_1.__importDefault(require("./templates/ssr.html.template"));
|
|
19
|
+
async function createServerConfig({ props, onLinksCollected, onHeadTagsCollected, }) {
|
|
20
|
+
const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, siteConfig: { noIndex, trailingSlash, ssrTemplate }, } = props;
|
|
21
|
+
const config = await (0, base_1.createBaseConfig)(props, true);
|
|
21
22
|
const routesLocation = {};
|
|
22
23
|
// Array of paths to be rendered. Relative to output directory
|
|
23
24
|
const ssgPaths = routesPaths.map((str) => {
|
|
@@ -25,8 +26,8 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
|
25
26
|
routesLocation[ssgPath] = str;
|
|
26
27
|
return ssgPath;
|
|
27
28
|
});
|
|
28
|
-
const serverConfig = webpack_merge_1.default(config, {
|
|
29
|
-
target: `node${
|
|
29
|
+
const serverConfig = (0, webpack_merge_1.default)(config, {
|
|
30
|
+
target: `node${utils_1.NODE_MAJOR_VERSION}.${utils_1.NODE_MINOR_VERSION}`,
|
|
30
31
|
entry: {
|
|
31
32
|
main: path_1.default.resolve(__dirname, '../client/serverEntry.js'),
|
|
32
33
|
},
|
|
@@ -52,11 +53,23 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
|
52
53
|
preBodyTags,
|
|
53
54
|
postBodyTags,
|
|
54
55
|
onLinksCollected,
|
|
55
|
-
|
|
56
|
+
onHeadTagsCollected,
|
|
57
|
+
ssrTemplate: ssrTemplate ?? ssr_html_template_1.default,
|
|
56
58
|
noIndex,
|
|
59
|
+
DOCUSAURUS_VERSION: utils_1.DOCUSAURUS_VERSION,
|
|
57
60
|
},
|
|
58
61
|
paths: ssgPaths,
|
|
59
62
|
preferFoldersOutput: trailingSlash,
|
|
63
|
+
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
64
|
+
// __filename, and this plugin will throw. not sure the __filename value
|
|
65
|
+
// has any importance for this plugin, just using an empty string to
|
|
66
|
+
// avoid the error. See https://github.com/facebook/docusaurus/issues/4922
|
|
67
|
+
globals: { __filename: '' },
|
|
68
|
+
// Secret way to set SSR plugin concurrency option
|
|
69
|
+
// Waiting for feedback before documenting this officially?
|
|
70
|
+
concurrency: process.env.DOCUSAURUS_SSR_CONCURRENCY
|
|
71
|
+
? parseInt(process.env.DOCUSAURUS_SSR_CONCURRENCY, 10)
|
|
72
|
+
: undefined,
|
|
60
73
|
}),
|
|
61
74
|
// Show compilation progress bar.
|
|
62
75
|
new LogPlugin_1.default({
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
declare const _default: "\n<!DOCTYPE html>\n<html <%~ it.htmlAttributes %>>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"generator\" content=\"Docusaurus v<%= it.version %>\">\n <% if (it.noIndex) { %>\n <meta name=\"robots\" content=\"noindex, nofollow\" />\n <% } %>\n <%~ it.headTags %>\n <% it.metaAttributes.forEach((metaAttribute) => { %>\n <%~ metaAttribute %>\n <% }); %>\n <% it.stylesheets.forEach((stylesheet) => { %>\n <link rel=\"stylesheet\" href=\"<%= it.baseUrl %><%= stylesheet %>\" />\n <% }); %>\n <% it.scripts.forEach((script) => { %>\n <link rel=\"preload\" href=\"<%= it.baseUrl %><%= script %>\" as=\"script\">\n <% }); %>\n </head>\n <body <%~ it.bodyAttributes %>>\n <%~ it.preBodyTags %>\n <div id=\"__docusaurus\">\n <%~ it.appHtml %>\n </div>\n <% it.scripts.forEach((script) => { %>\n <script src=\"<%= it.baseUrl %><%= script %>\"></script>\n <% }); %>\n <%~ it.postBodyTags %>\n </body>\n</html>\n";
|
|
8
|
+
export default _default;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = `
|
|
9
10
|
<!DOCTYPE html>
|
|
10
11
|
<html <%~ it.htmlAttributes %>>
|
|
11
12
|
<head>
|
package/lib/webpack/utils.d.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="node" />
|
|
8
|
-
import { Configuration, RuleSetRule, WebpackPluginInstance } from 'webpack';
|
|
9
|
-
import { TransformOptions } from '@babel/core';
|
|
10
|
-
import {
|
|
11
|
-
export declare function getStyleLoaders(isServer: boolean,
|
|
8
|
+
import { type Configuration, type RuleSetRule, type WebpackPluginInstance } from 'webpack';
|
|
9
|
+
import type { TransformOptions } from '@babel/core';
|
|
10
|
+
import type { Plugin } from '@docusaurus/types';
|
|
11
|
+
export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
|
|
12
12
|
[key: string]: unknown;
|
|
13
13
|
}): RuleSetRule[];
|
|
14
|
-
export declare function getCustomBabelConfigFilePath(siteDir: string): string | undefined
|
|
14
|
+
export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
|
|
15
15
|
export declare function getBabelOptions({ isServer, babelOptions, }?: {
|
|
16
16
|
isServer?: boolean;
|
|
17
17
|
babelOptions?: TransformOptions | string;
|
|
@@ -29,33 +29,17 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
|
|
|
29
29
|
* @param content content loaded by the plugin
|
|
30
30
|
* @returns final/ modified webpack config
|
|
31
31
|
*/
|
|
32
|
-
export declare function applyConfigureWebpack(configureWebpack:
|
|
33
|
-
export declare function applyConfigurePostCss(configurePostCss: NonNullable<
|
|
32
|
+
export declare function applyConfigureWebpack(configureWebpack: NonNullable<Plugin['configureWebpack']>, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
|
|
33
|
+
export declare function applyConfigurePostCss(configurePostCss: NonNullable<Plugin['configurePostCss']>, config: Configuration): Configuration;
|
|
34
|
+
declare global {
|
|
35
|
+
interface Error {
|
|
36
|
+
/** @see https://webpack.js.org/api/node/#error-handling */
|
|
37
|
+
details: unknown;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
34
40
|
export declare function compile(config: Configuration[]): Promise<void>;
|
|
35
|
-
declare
|
|
36
|
-
declare type FileLoaderUtils = {
|
|
37
|
-
loaders: {
|
|
38
|
-
file: (options: {
|
|
39
|
-
folder: AssetFolder;
|
|
40
|
-
}) => RuleSetRule;
|
|
41
|
-
url: (options: {
|
|
42
|
-
folder: AssetFolder;
|
|
43
|
-
}) => RuleSetRule;
|
|
44
|
-
inlineMarkdownImageFileLoader: string;
|
|
45
|
-
inlineMarkdownLinkFileLoader: string;
|
|
46
|
-
};
|
|
47
|
-
rules: {
|
|
48
|
-
images: () => RuleSetRule;
|
|
49
|
-
fonts: () => RuleSetRule;
|
|
50
|
-
media: () => RuleSetRule;
|
|
51
|
-
svg: () => RuleSetRule;
|
|
52
|
-
otherAssets: () => RuleSetRule;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export declare function getFileLoaderUtils(): FileLoaderUtils;
|
|
56
|
-
export declare function getHttpsConfig(): boolean | {
|
|
41
|
+
export declare function getHttpsConfig(): Promise<boolean | {
|
|
57
42
|
cert: Buffer;
|
|
58
43
|
key: Buffer;
|
|
59
|
-
}
|
|
44
|
+
}>;
|
|
60
45
|
export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
|
|
61
|
-
export {};
|
package/lib/webpack/utils.js
CHANGED
|
@@ -6,21 +6,25 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getMinimizer = exports.getHttpsConfig = exports.
|
|
9
|
+
exports.getMinimizer = exports.getHttpsConfig = exports.compile = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = void 0;
|
|
10
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 crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
11
16
|
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
12
17
|
const webpack_merge_1 = require("webpack-merge");
|
|
13
18
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
14
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
15
19
|
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
16
20
|
const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
|
|
17
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
18
|
-
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
19
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
20
|
-
const constants_1 = require("../constants");
|
|
21
|
-
const lodash_1 = require("lodash");
|
|
22
21
|
// Utility method to get style loaders
|
|
23
|
-
function getStyleLoaders(isServer,
|
|
22
|
+
function getStyleLoaders(isServer, cssOptionsArg = {}) {
|
|
23
|
+
const cssOptions = {
|
|
24
|
+
// TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
|
|
25
|
+
esModule: false,
|
|
26
|
+
...cssOptionsArg,
|
|
27
|
+
};
|
|
24
28
|
if (isServer) {
|
|
25
29
|
return cssOptions.modules
|
|
26
30
|
? [
|
|
@@ -66,7 +70,7 @@ function getStyleLoaders(isServer, cssOptions = {}) {
|
|
|
66
70
|
// https://github.com/facebook/create-react-app/issues/2677
|
|
67
71
|
ident: 'postcss',
|
|
68
72
|
plugins: [
|
|
69
|
-
// eslint-disable-next-line
|
|
73
|
+
// eslint-disable-next-line global-require
|
|
70
74
|
require('autoprefixer'),
|
|
71
75
|
],
|
|
72
76
|
},
|
|
@@ -75,9 +79,9 @@ function getStyleLoaders(isServer, cssOptions = {}) {
|
|
|
75
79
|
];
|
|
76
80
|
}
|
|
77
81
|
exports.getStyleLoaders = getStyleLoaders;
|
|
78
|
-
function getCustomBabelConfigFilePath(siteDir) {
|
|
79
|
-
const customBabelConfigurationPath = path_1.default.join(siteDir,
|
|
80
|
-
return fs_extra_1.default.
|
|
82
|
+
async function getCustomBabelConfigFilePath(siteDir) {
|
|
83
|
+
const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
|
|
84
|
+
return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
|
|
81
85
|
? customBabelConfigurationPath
|
|
82
86
|
: undefined;
|
|
83
87
|
}
|
|
@@ -90,13 +94,12 @@ function getBabelOptions({ isServer, babelOptions, } = {}) {
|
|
|
90
94
|
caller: { name: isServer ? 'server' : 'client' },
|
|
91
95
|
};
|
|
92
96
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
97
|
+
return {
|
|
98
|
+
...(babelOptions ?? { presets: [require.resolve('../babel/preset')] }),
|
|
99
|
+
babelrc: false,
|
|
100
|
+
configFile: false,
|
|
101
|
+
caller: { name: isServer ? 'server' : 'client' },
|
|
102
|
+
};
|
|
100
103
|
}
|
|
101
104
|
exports.getBabelOptions = getBabelOptions;
|
|
102
105
|
// Name is generic on purpose
|
|
@@ -111,22 +114,6 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
|
|
|
111
114
|
? getDefaultBabelLoader({ isServer, babelOptions })
|
|
112
115
|
: jsLoader(isServer);
|
|
113
116
|
exports.getCustomizableJSLoader = getCustomizableJSLoader;
|
|
114
|
-
// TODO remove this before end of 2021?
|
|
115
|
-
const warnBabelLoaderOnce = lodash_1.memoize(function () {
|
|
116
|
-
console.warn(chalk_1.default.yellow('Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): "getBabelLoader(isServer)" is now deprecated in favor of "getJSLoader({isServer})".'));
|
|
117
|
-
});
|
|
118
|
-
const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, babelOptions) {
|
|
119
|
-
warnBabelLoaderOnce();
|
|
120
|
-
return getDefaultBabelLoader({ isServer, babelOptions });
|
|
121
|
-
};
|
|
122
|
-
// TODO remove this before end of 2021 ?
|
|
123
|
-
const warnCacheLoaderOnce = lodash_1.memoize(function () {
|
|
124
|
-
console.warn(chalk_1.default.yellow('Docusaurus uses Webpack 5 and getCacheLoader() usage is now deprecated.'));
|
|
125
|
-
});
|
|
126
|
-
function getCacheLoaderDeprecated() {
|
|
127
|
-
warnCacheLoaderOnce();
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
117
|
/**
|
|
131
118
|
* Helper function to modify webpack config
|
|
132
119
|
* @param configureWebpack a webpack config or a function to modify config
|
|
@@ -140,30 +127,23 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
|
|
|
140
127
|
// Export some utility functions
|
|
141
128
|
const utils = {
|
|
142
129
|
getStyleLoaders,
|
|
143
|
-
getJSLoader: exports.getCustomizableJSLoader(jsLoader),
|
|
144
|
-
getBabelLoader: getBabelLoaderDeprecated,
|
|
145
|
-
getCacheLoader: getCacheLoaderDeprecated,
|
|
130
|
+
getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
|
|
146
131
|
};
|
|
147
132
|
if (typeof configureWebpack === 'function') {
|
|
148
|
-
const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
customizeObject: webpack_merge_1.customizeObject(customizeRules),
|
|
155
|
-
})(config, res);
|
|
156
|
-
}
|
|
133
|
+
const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
|
|
134
|
+
const customizeRules = mergeStrategy ?? {};
|
|
135
|
+
return (0, webpack_merge_1.mergeWithCustomize)({
|
|
136
|
+
customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
|
|
137
|
+
customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
|
|
138
|
+
})(config, res);
|
|
157
139
|
}
|
|
158
140
|
return config;
|
|
159
141
|
}
|
|
160
142
|
exports.applyConfigureWebpack = applyConfigureWebpack;
|
|
161
143
|
function applyConfigurePostCss(configurePostCss, config) {
|
|
162
|
-
|
|
163
|
-
// TODO not ideal heuristic but good enough for our usecase?
|
|
144
|
+
// Not ideal heuristic but good enough for our use-case?
|
|
164
145
|
function isPostCssLoader(loader) {
|
|
165
|
-
|
|
166
|
-
return !!((_b = (_a = loader) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.postcssOptions);
|
|
146
|
+
return !!loader?.options?.postcssOptions;
|
|
167
147
|
}
|
|
168
148
|
// Does not handle all edge cases, but good enough for now
|
|
169
149
|
function overridePostCssOptions(entry) {
|
|
@@ -176,42 +156,39 @@ function applyConfigurePostCss(configurePostCss, config) {
|
|
|
176
156
|
else if (Array.isArray(entry.use)) {
|
|
177
157
|
entry.use
|
|
178
158
|
.filter((u) => typeof u === 'object')
|
|
179
|
-
.forEach(overridePostCssOptions);
|
|
159
|
+
.forEach((rule) => overridePostCssOptions(rule));
|
|
180
160
|
}
|
|
181
161
|
}
|
|
182
|
-
|
|
162
|
+
config.module?.rules?.forEach((rule) => overridePostCssOptions(rule));
|
|
183
163
|
return config;
|
|
184
164
|
}
|
|
185
165
|
exports.applyConfigurePostCss = applyConfigurePostCss;
|
|
186
166
|
function compile(config) {
|
|
187
167
|
return new Promise((resolve, reject) => {
|
|
188
|
-
const compiler = webpack_1.default(config);
|
|
168
|
+
const compiler = (0, webpack_1.default)(config);
|
|
189
169
|
compiler.run((err, stats) => {
|
|
190
|
-
var _a;
|
|
191
170
|
if (err) {
|
|
192
|
-
|
|
193
|
-
// @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
|
|
171
|
+
logger_1.default.error(err.stack ?? err);
|
|
194
172
|
if (err.details) {
|
|
195
|
-
|
|
196
|
-
console.error(err.details);
|
|
173
|
+
logger_1.default.error(err.details);
|
|
197
174
|
}
|
|
198
175
|
reject(err);
|
|
199
176
|
}
|
|
200
|
-
//
|
|
201
|
-
const errorsWarnings = stats
|
|
202
|
-
if (stats
|
|
177
|
+
// Let plugins consume all the stats
|
|
178
|
+
const errorsWarnings = stats?.toJson('errors-warnings');
|
|
179
|
+
if (stats?.hasErrors()) {
|
|
203
180
|
reject(new Error('Failed to compile with errors.'));
|
|
204
181
|
}
|
|
205
|
-
if (errorsWarnings &&
|
|
206
|
-
|
|
207
|
-
|
|
182
|
+
if (errorsWarnings && stats?.hasWarnings()) {
|
|
183
|
+
errorsWarnings.warnings?.forEach((warning) => {
|
|
184
|
+
logger_1.default.warn(warning);
|
|
208
185
|
});
|
|
209
186
|
}
|
|
210
187
|
// Webpack 5 requires calling close() so that persistent caching works
|
|
211
188
|
// See https://github.com/webpack/webpack.js.org/pull/4775
|
|
212
189
|
compiler.close((errClose) => {
|
|
213
190
|
if (errClose) {
|
|
214
|
-
|
|
191
|
+
logger_1.default.error(`Error while closing Webpack compiler: ${errClose}`);
|
|
215
192
|
reject(errClose);
|
|
216
193
|
}
|
|
217
194
|
else {
|
|
@@ -222,145 +199,46 @@ function compile(config) {
|
|
|
222
199
|
});
|
|
223
200
|
}
|
|
224
201
|
exports.compile = compile;
|
|
225
|
-
// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
226
|
-
function getFileLoaderUtils() {
|
|
227
|
-
// files/images < 10kb will be inlined as base64 strings directly in the html
|
|
228
|
-
const urlLoaderLimit = 10000;
|
|
229
|
-
// defines the path/pattern of the assets handled by webpack
|
|
230
|
-
const fileLoaderFileName = (folder) => `${constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[hash].[ext]`;
|
|
231
|
-
const loaders = {
|
|
232
|
-
file: (options) => {
|
|
233
|
-
return {
|
|
234
|
-
loader: require.resolve(`file-loader`),
|
|
235
|
-
options: {
|
|
236
|
-
name: fileLoaderFileName(options.folder),
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
},
|
|
240
|
-
url: (options) => {
|
|
241
|
-
return {
|
|
242
|
-
loader: require.resolve(`url-loader`),
|
|
243
|
-
options: {
|
|
244
|
-
limit: urlLoaderLimit,
|
|
245
|
-
name: fileLoaderFileName(options.folder),
|
|
246
|
-
fallback: require.resolve(`file-loader`),
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
},
|
|
250
|
-
// TODO find a better solution to avoid conflicts with the ideal-image plugin
|
|
251
|
-
// TODO this may require a little breaking change for ideal-image users?
|
|
252
|
-
// Maybe with the ideal image plugin, all md images should be "ideal"?
|
|
253
|
-
// This is used to force url-loader+file-loader on markdown images
|
|
254
|
-
// https://webpack.js.org/concepts/loaders/#inline
|
|
255
|
-
inlineMarkdownImageFileLoader: `!url-loader?limit=${urlLoaderLimit}&name=${fileLoaderFileName('images')}&fallback=file-loader!`,
|
|
256
|
-
inlineMarkdownLinkFileLoader: `!file-loader?name=${fileLoaderFileName('files')}!`,
|
|
257
|
-
};
|
|
258
|
-
const rules = {
|
|
259
|
-
/**
|
|
260
|
-
* Loads image assets, inlines images via a data URI if they are below
|
|
261
|
-
* the size threshold
|
|
262
|
-
*/
|
|
263
|
-
images: () => {
|
|
264
|
-
return {
|
|
265
|
-
use: [loaders.url({ folder: 'images' })],
|
|
266
|
-
test: /\.(ico|jpg|jpeg|png|gif|webp)(\?.*)?$/,
|
|
267
|
-
};
|
|
268
|
-
},
|
|
269
|
-
fonts: () => {
|
|
270
|
-
return {
|
|
271
|
-
use: [loaders.url({ folder: 'fonts' })],
|
|
272
|
-
test: /\.(woff|woff2|eot|ttf|otf)$/,
|
|
273
|
-
};
|
|
274
|
-
},
|
|
275
|
-
/**
|
|
276
|
-
* Loads audio and video and inlines them via a data URI if they are below
|
|
277
|
-
* the size threshold
|
|
278
|
-
*/
|
|
279
|
-
media: () => {
|
|
280
|
-
return {
|
|
281
|
-
use: [loaders.url({ folder: 'medias' })],
|
|
282
|
-
test: /\.(mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/,
|
|
283
|
-
};
|
|
284
|
-
},
|
|
285
|
-
svg: () => {
|
|
286
|
-
return {
|
|
287
|
-
test: /\.svg?$/,
|
|
288
|
-
oneOf: [
|
|
289
|
-
{
|
|
290
|
-
use: [
|
|
291
|
-
{
|
|
292
|
-
loader: '@svgr/webpack',
|
|
293
|
-
options: {
|
|
294
|
-
prettier: false,
|
|
295
|
-
svgo: true,
|
|
296
|
-
svgoConfig: {
|
|
297
|
-
plugins: [{ removeViewBox: false }],
|
|
298
|
-
},
|
|
299
|
-
titleProp: true,
|
|
300
|
-
ref: ![path_1.default],
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
],
|
|
304
|
-
// We don't want to use SVGR loader for non-React source code
|
|
305
|
-
// ie we don't want to use SVGR for CSS files...
|
|
306
|
-
issuer: {
|
|
307
|
-
and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
use: [loaders.url({ folder: 'images' })],
|
|
312
|
-
},
|
|
313
|
-
],
|
|
314
|
-
};
|
|
315
|
-
},
|
|
316
|
-
otherAssets: () => {
|
|
317
|
-
return {
|
|
318
|
-
use: [loaders.file({ folder: 'files' })],
|
|
319
|
-
test: /\.(pdf|doc|docx|xls|xlsx|zip|rar)$/,
|
|
320
|
-
};
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
return { loaders, rules };
|
|
324
|
-
}
|
|
325
|
-
exports.getFileLoaderUtils = getFileLoaderUtils;
|
|
326
202
|
// Ensure the certificate and key provided are valid and if not
|
|
327
203
|
// throw an easy to debug error
|
|
328
|
-
function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
|
|
204
|
+
function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
|
|
329
205
|
let encrypted;
|
|
330
206
|
try {
|
|
331
207
|
// publicEncrypt will throw an error with an invalid cert
|
|
332
208
|
encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
|
|
333
209
|
}
|
|
334
210
|
catch (err) {
|
|
335
|
-
|
|
211
|
+
logger_1.default.error `The certificate path=${crtFile} is invalid.`;
|
|
212
|
+
throw err;
|
|
336
213
|
}
|
|
337
214
|
try {
|
|
338
215
|
// privateDecrypt will throw an error with an invalid key
|
|
339
216
|
crypto_1.default.privateDecrypt(key, encrypted);
|
|
340
217
|
}
|
|
341
218
|
catch (err) {
|
|
342
|
-
|
|
219
|
+
logger_1.default.error `The certificate key path=${keyFile} is invalid.`;
|
|
220
|
+
throw err;
|
|
343
221
|
}
|
|
344
222
|
}
|
|
345
223
|
// Read file and throw an error if it doesn't exist
|
|
346
|
-
function readEnvFile(file, type) {
|
|
347
|
-
if (!fs_extra_1.default.
|
|
348
|
-
throw new Error(`You specified ${
|
|
224
|
+
async function readEnvFile(file, type) {
|
|
225
|
+
if (!(await fs_extra_1.default.pathExists(file))) {
|
|
226
|
+
throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
|
|
349
227
|
}
|
|
350
|
-
return fs_extra_1.default.
|
|
228
|
+
return fs_extra_1.default.readFile(file);
|
|
351
229
|
}
|
|
352
|
-
const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
|
|
353
230
|
// Get the https config
|
|
354
231
|
// Return cert files if provided in env, otherwise just true or false
|
|
355
|
-
function getHttpsConfig() {
|
|
232
|
+
async function getHttpsConfig() {
|
|
233
|
+
const appDirectory = await fs_extra_1.default.realpath(process.cwd());
|
|
356
234
|
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
|
|
357
235
|
const isHttps = HTTPS === 'true';
|
|
358
236
|
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
|
|
359
237
|
const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
|
|
360
238
|
const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
|
|
361
239
|
const config = {
|
|
362
|
-
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
|
|
363
|
-
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
|
|
240
|
+
cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
|
|
241
|
+
key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
|
|
364
242
|
};
|
|
365
243
|
validateKeyAndCerts({ ...config, keyFile, crtFile });
|
|
366
244
|
return config;
|
|
@@ -386,12 +264,12 @@ function getMinimizer(useSimpleCssMinifier = false) {
|
|
|
386
264
|
parallel: getTerserParallel(),
|
|
387
265
|
terserOptions: {
|
|
388
266
|
parse: {
|
|
389
|
-
//
|
|
267
|
+
// We want uglify-js to parse ecma 8 code. However, we don't want it
|
|
390
268
|
// to apply any minification steps that turns valid ecma 5 code
|
|
391
269
|
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
392
270
|
// sections only apply transformations that are ecma 5 safe
|
|
393
271
|
// https://github.com/facebook/create-react-app/pull/4234
|
|
394
|
-
ecma:
|
|
272
|
+
ecma: 2020,
|
|
395
273
|
},
|
|
396
274
|
compress: {
|
|
397
275
|
ecma: 5,
|
|
@@ -403,8 +281,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
|
|
|
403
281
|
output: {
|
|
404
282
|
ecma: 5,
|
|
405
283
|
comments: false,
|
|
406
|
-
// Turned on because emoji and regex is not minified properly using
|
|
407
|
-
// https://github.com/facebook/create-react-app/issues/2488
|
|
284
|
+
// Turned on because emoji and regex is not minified properly using
|
|
285
|
+
// default. See https://github.com/facebook/create-react-app/issues/2488
|
|
408
286
|
ascii_only: true,
|
|
409
287
|
},
|
|
410
288
|
},
|
|
@@ -429,6 +307,7 @@ function getMinimizer(useSimpleCssMinifier = false) {
|
|
|
429
307
|
level: {
|
|
430
308
|
1: {
|
|
431
309
|
all: false,
|
|
310
|
+
removeWhitespace: true,
|
|
432
311
|
},
|
|
433
312
|
2: {
|
|
434
313
|
all: true,
|