@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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/beforeCli.mjs +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +29 -38
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +13 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -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 +1 -1
- package/lib/client/exports/Interpolate.js +16 -22
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +24 -19
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +14 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- 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 +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.js +1 -5
- 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/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +39 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +6 -6
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +102 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +3 -3
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +13 -19
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +93 -83
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -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 +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -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 +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +103 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +41 -43
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +35 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +57 -38
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +7 -4
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +43 -28
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +2 -4
- package/lib/server/html-tags/index.d.ts +1 -1
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +32 -46
- package/lib/server/index.d.ts +2 -2
- package/lib/server/index.js +147 -68
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +2 -2
- package/lib/server/plugins/index.js +34 -35
- package/lib/server/plugins/init.d.ts +12 -2
- package/lib/server/plugins/init.js +48 -58
- package/lib/server/plugins/pluginIds.d.ts +1 -1
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +12 -13
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +50 -29
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -14
- package/lib/server/themes/index.d.ts +3 -3
- package/lib/server/themes/index.js +26 -26
- package/lib/server/translations/translations.d.ts +7 -1
- package/lib/server/translations/translations.js +30 -45
- package/lib/server/translations/translationsExtractor.d.ts +9 -3
- package/lib/server/translations/translationsExtractor.js +159 -120
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +38 -33
- 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 +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +9 -8
- 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 +7 -29
- package/lib/webpack/utils.js +54 -171
- package/package.json +74 -69
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- 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/loadSetup.js +0 -25
- package/lib/server/versions/__tests/index.test.js +0 -25
- 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.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -6,45 +6,46 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getPluginVersion = exports.
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
exports.getPluginVersion = exports.getPackageJsonVersion = 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
|
+
async function getPackageJsonVersion(packageJsonPath) {
|
|
14
|
+
if (await fs_extra_1.default.pathExists(packageJsonPath)) {
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
15
|
-
|
|
16
|
-
return typeof version === 'string' ? version : undefined;
|
|
16
|
+
return require(packageJsonPath).version;
|
|
17
17
|
}
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
exports.getPackageJsonVersion = getPackageJsonVersion;
|
|
21
|
-
function getPackageJsonName(packageJsonPath) {
|
|
22
|
-
if (fs_extra_1.
|
|
21
|
+
async function getPackageJsonName(packageJsonPath) {
|
|
22
|
+
if (await fs_extra_1.default.pathExists(packageJsonPath)) {
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
24
|
-
|
|
25
|
-
return typeof name === 'string' ? name : undefined;
|
|
24
|
+
return require(packageJsonPath).name;
|
|
26
25
|
}
|
|
27
26
|
return undefined;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let potentialPluginPackageJsonDirectory = path_1.dirname(pluginPath);
|
|
28
|
+
async function getPluginVersion(pluginPath, siteDir) {
|
|
29
|
+
let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
|
|
32
30
|
while (potentialPluginPackageJsonDirectory !== '/') {
|
|
33
|
-
const packageJsonPath = path_1.join(potentialPluginPackageJsonDirectory, 'package.json');
|
|
34
|
-
if (
|
|
31
|
+
const packageJsonPath = path_1.default.join(potentialPluginPackageJsonDirectory, 'package.json');
|
|
32
|
+
if ((await fs_extra_1.default.pathExists(packageJsonPath)) &&
|
|
33
|
+
(await fs_extra_1.default.lstat(packageJsonPath)).isFile()) {
|
|
35
34
|
if (potentialPluginPackageJsonDirectory === siteDir) {
|
|
36
|
-
// If the plugin belongs to the same docusaurus project, we classify it
|
|
35
|
+
// If the plugin belongs to the same docusaurus project, we classify it
|
|
36
|
+
// as local plugin.
|
|
37
37
|
return { type: 'project' };
|
|
38
38
|
}
|
|
39
39
|
return {
|
|
40
40
|
type: 'package',
|
|
41
|
-
name: getPackageJsonName(packageJsonPath),
|
|
42
|
-
version: getPackageJsonVersion(packageJsonPath),
|
|
41
|
+
name: await getPackageJsonName(packageJsonPath),
|
|
42
|
+
version: await getPackageJsonVersion(packageJsonPath),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
potentialPluginPackageJsonDirectory = path_1.dirname(potentialPluginPackageJsonDirectory);
|
|
45
|
+
potentialPluginPackageJsonDirectory = path_1.default.dirname(potentialPluginPackageJsonDirectory);
|
|
46
46
|
}
|
|
47
|
-
// In
|
|
47
|
+
// In the case where a plugin is a path where no parent directory contains
|
|
48
|
+
// package.json (e.g. inline plugin), we can only classify it as local.
|
|
48
49
|
return { type: 'local' };
|
|
49
50
|
}
|
|
50
51
|
exports.getPluginVersion = getPluginVersion;
|
package/lib/webpack/base.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
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 { Configuration } from 'webpack';
|
|
8
|
-
import { Props } from '@docusaurus/types';
|
|
7
|
+
import type { Configuration } from 'webpack';
|
|
8
|
+
import type { Props } from '@docusaurus/types';
|
|
9
9
|
export declare const clientDir: string;
|
|
10
10
|
export declare function excludeJS(modulePath: string): boolean;
|
|
11
|
-
export declare function getDocusaurusAliases(): Record<string, string
|
|
12
|
-
export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Configuration
|
|
11
|
+
export declare function getDocusaurusAliases(): Promise<Record<string, string>>;
|
|
12
|
+
export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;
|
package/lib/webpack/base.js
CHANGED
|
@@ -12,12 +12,10 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
|
12
12
|
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
13
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
|
-
const constants_1 = require("../constants");
|
|
16
|
-
const sharedModuleAliases_1 = tslib_1.__importDefault(require("./sharedModuleAliases"));
|
|
17
15
|
const themes_1 = require("../server/themes");
|
|
18
16
|
const utils_2 = require("@docusaurus/utils");
|
|
19
|
-
const CSS_REGEX = /\.css
|
|
20
|
-
const CSS_MODULE_REGEX = /\.module\.css
|
|
17
|
+
const CSS_REGEX = /\.css$/i;
|
|
18
|
+
const CSS_MODULE_REGEX = /\.module\.css$/i;
|
|
21
19
|
exports.clientDir = path_1.default.join(__dirname, '..', 'client');
|
|
22
20
|
const LibrariesToTranspile = [
|
|
23
21
|
'copy-text-to-clipboard', // contains optional catch binding, incompatible with recent versions of Edge
|
|
@@ -30,15 +28,15 @@ function excludeJS(modulePath) {
|
|
|
30
28
|
}
|
|
31
29
|
// Don't transpile node_modules except any docusaurus npm package
|
|
32
30
|
return (/node_modules/.test(modulePath) &&
|
|
33
|
-
!/
|
|
31
|
+
!/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
|
|
34
32
|
!LibrariesToTranspileRegex.test(modulePath));
|
|
35
33
|
}
|
|
36
34
|
exports.excludeJS = excludeJS;
|
|
37
|
-
function getDocusaurusAliases() {
|
|
35
|
+
async function getDocusaurusAliases() {
|
|
38
36
|
const dirPath = path_1.default.resolve(__dirname, '../client/exports');
|
|
39
37
|
const extensions = ['.js', '.ts', '.tsx'];
|
|
40
38
|
const aliases = {};
|
|
41
|
-
fs_extra_1.default.
|
|
39
|
+
(await fs_extra_1.default.readdir(dirPath))
|
|
42
40
|
.filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
|
|
43
41
|
.forEach((fileName) => {
|
|
44
42
|
const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
|
|
@@ -48,17 +46,16 @@ function getDocusaurusAliases() {
|
|
|
48
46
|
return aliases;
|
|
49
47
|
}
|
|
50
48
|
exports.getDocusaurusAliases = getDocusaurusAliases;
|
|
51
|
-
function createBaseConfig(props, isServer, minify = true) {
|
|
52
|
-
var _a;
|
|
49
|
+
async function createBaseConfig(props, isServer, minify = true) {
|
|
53
50
|
const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
|
|
54
51
|
const totalPages = routesPaths.length;
|
|
55
52
|
const isProd = process.env.NODE_ENV === 'production';
|
|
56
53
|
const minimizeEnabled = minify && isProd && !isServer;
|
|
57
54
|
const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
|
|
58
|
-
const fileLoaderUtils =
|
|
55
|
+
const fileLoaderUtils = (0, utils_2.getFileLoaderUtils)();
|
|
59
56
|
const name = isServer ? 'server' : 'client';
|
|
60
57
|
const mode = isProd ? 'production' : 'development';
|
|
61
|
-
const themeAliases = themes_1.loadPluginsThemeAliases({ siteDir, plugins });
|
|
58
|
+
const themeAliases = await (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
|
|
62
59
|
return {
|
|
63
60
|
mode,
|
|
64
61
|
name,
|
|
@@ -71,16 +68,19 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
71
68
|
// When version string changes, cache is evicted
|
|
72
69
|
version: [
|
|
73
70
|
siteMetadata.docusaurusVersion,
|
|
74
|
-
// Webpack does not evict the cache correctly on alias/swizzle change,
|
|
71
|
+
// Webpack does not evict the cache correctly on alias/swizzle change,
|
|
72
|
+
// so we force eviction.
|
|
75
73
|
// See https://github.com/webpack/webpack/issues/13627
|
|
76
|
-
utils_2.md5Hash(JSON.stringify(themeAliases)),
|
|
74
|
+
(0, utils_2.md5Hash)(JSON.stringify(themeAliases)),
|
|
77
75
|
].join('-'),
|
|
78
|
-
// When one of those modules/dependencies change (including transitive
|
|
76
|
+
// When one of those modules/dependencies change (including transitive
|
|
77
|
+
// deps), cache is invalidated
|
|
79
78
|
buildDependencies: {
|
|
80
79
|
config: [
|
|
81
80
|
__filename,
|
|
82
81
|
path_1.default.join(__dirname, isServer ? 'server.js' : 'client.js'),
|
|
83
|
-
// Docusaurus config changes can affect MDX/JSX compilation, so we'd
|
|
82
|
+
// Docusaurus config changes can affect MDX/JSX compilation, so we'd
|
|
83
|
+
// rather evict the cache.
|
|
84
84
|
// See https://github.com/questdb/questdb.io/issues/493
|
|
85
85
|
siteConfigPath,
|
|
86
86
|
],
|
|
@@ -94,6 +94,7 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
94
94
|
? 'assets/js/[name].[contenthash:8].js'
|
|
95
95
|
: '[name].js',
|
|
96
96
|
publicPath: baseUrl,
|
|
97
|
+
hashFunction: 'xxhash64',
|
|
97
98
|
},
|
|
98
99
|
// Don't throw warning when asset created is over 250kb
|
|
99
100
|
performance: {
|
|
@@ -108,28 +109,28 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
108
109
|
// Allow resolution of url("/fonts/xyz.ttf") by webpack
|
|
109
110
|
// See https://webpack.js.org/configuration/resolve/#resolveroots
|
|
110
111
|
// See https://github.com/webpack-contrib/css-loader/issues/1256
|
|
111
|
-
path_1.default.
|
|
112
|
+
...siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
112
113
|
siteDir,
|
|
113
114
|
process.cwd(),
|
|
114
115
|
],
|
|
115
116
|
alias: {
|
|
116
|
-
...sharedModuleAliases_1.default,
|
|
117
117
|
'@site': siteDir,
|
|
118
118
|
'@generated': generatedFilesDir,
|
|
119
119
|
// Note: a @docusaurus alias would also catch @docusaurus/theme-common,
|
|
120
120
|
// so we use fine-grained aliases instead
|
|
121
121
|
// '@docusaurus': path.resolve(__dirname, '../client/exports'),
|
|
122
|
-
...getDocusaurusAliases(),
|
|
122
|
+
...(await getDocusaurusAliases()),
|
|
123
123
|
...themeAliases,
|
|
124
124
|
},
|
|
125
|
-
// This allows you to set a fallback for where Webpack should look for
|
|
126
|
-
// We want `@docusaurus/core` own dependencies/`node_modules` to
|
|
127
|
-
// Example: if there is core-js@3 in user's
|
|
128
|
-
// core-js@2, we should use
|
|
125
|
+
// This allows you to set a fallback for where Webpack should look for
|
|
126
|
+
// modules. We want `@docusaurus/core` own dependencies/`node_modules` to
|
|
127
|
+
// "win" if there is conflict. Example: if there is core-js@3 in user's
|
|
128
|
+
// own node_modules, but core depends on core-js@2, we should use
|
|
129
|
+
// core-js@2.
|
|
129
130
|
modules: [
|
|
130
131
|
path_1.default.resolve(__dirname, '..', '..', 'node_modules'),
|
|
131
132
|
'node_modules',
|
|
132
|
-
path_1.default.resolve(fs_extra_1.default.
|
|
133
|
+
path_1.default.resolve(await fs_extra_1.default.realpath(process.cwd()), 'node_modules'),
|
|
133
134
|
],
|
|
134
135
|
},
|
|
135
136
|
resolveLoader: {
|
|
@@ -137,15 +138,18 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
137
138
|
},
|
|
138
139
|
optimization: {
|
|
139
140
|
removeAvailableModules: false,
|
|
140
|
-
// Only minimize client bundle in production because server bundle is only
|
|
141
|
+
// Only minimize client bundle in production because server bundle is only
|
|
142
|
+
// used for static site generation
|
|
141
143
|
minimize: minimizeEnabled,
|
|
142
144
|
minimizer: minimizeEnabled
|
|
143
|
-
? utils_1.getMinimizer(useSimpleCssMinifier)
|
|
145
|
+
? (0, utils_1.getMinimizer)(useSimpleCssMinifier)
|
|
144
146
|
: undefined,
|
|
145
147
|
splitChunks: isServer
|
|
146
148
|
? false
|
|
147
149
|
: {
|
|
148
|
-
// Since the chunk name includes all origin chunk names it's
|
|
150
|
+
// Since the chunk name includes all origin chunk names it's
|
|
151
|
+
// recommended for production builds with long term caching to NOT
|
|
152
|
+
// include [name] in the filenames
|
|
149
153
|
name: false,
|
|
150
154
|
cacheGroups: {
|
|
151
155
|
// disable the built-in cacheGroups
|
|
@@ -177,19 +181,19 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
177
181
|
fileLoaderUtils.rules.svg(),
|
|
178
182
|
fileLoaderUtils.rules.otherAssets(),
|
|
179
183
|
{
|
|
180
|
-
test: /\.
|
|
184
|
+
test: /\.[jt]sx?$/i,
|
|
181
185
|
exclude: excludeJS,
|
|
182
186
|
use: [
|
|
183
|
-
utils_1.getCustomizableJSLoader(
|
|
187
|
+
(0, utils_1.getCustomizableJSLoader)(siteConfig.webpack?.jsLoader)({
|
|
184
188
|
isServer,
|
|
185
|
-
babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
|
|
189
|
+
babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
186
190
|
}),
|
|
187
191
|
],
|
|
188
192
|
},
|
|
189
193
|
{
|
|
190
194
|
test: CSS_REGEX,
|
|
191
195
|
exclude: CSS_MODULE_REGEX,
|
|
192
|
-
use: utils_1.getStyleLoaders(isServer, {
|
|
196
|
+
use: (0, utils_1.getStyleLoaders)(isServer, {
|
|
193
197
|
importLoaders: 1,
|
|
194
198
|
sourceMap: !isProd,
|
|
195
199
|
}),
|
|
@@ -198,7 +202,7 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
198
202
|
// using the extension .module.css
|
|
199
203
|
{
|
|
200
204
|
test: CSS_MODULE_REGEX,
|
|
201
|
-
use: utils_1.getStyleLoaders(isServer, {
|
|
205
|
+
use: (0, utils_1.getStyleLoaders)(isServer, {
|
|
202
206
|
modules: {
|
|
203
207
|
localIdentName: isProd
|
|
204
208
|
? `[local]_[contenthash:base64:4]`
|
|
@@ -219,8 +223,9 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
219
223
|
chunkFilename: isProd
|
|
220
224
|
? 'assets/css/[name].[contenthash:8].css'
|
|
221
225
|
: '[name].css',
|
|
222
|
-
// remove css order warnings if css imports are not sorted
|
|
223
|
-
//
|
|
226
|
+
// remove css order warnings if css imports are not sorted
|
|
227
|
+
// alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
|
|
228
|
+
// for more reasoning
|
|
224
229
|
ignoreOrder: true,
|
|
225
230
|
}),
|
|
226
231
|
],
|
package/lib/webpack/client.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
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 { Configuration } from 'webpack';
|
|
8
|
-
import { Props } from '@docusaurus/types';
|
|
9
|
-
export default function createClientConfig(props: Props, minify?: boolean): Configuration
|
|
7
|
+
import type { Configuration } from 'webpack';
|
|
8
|
+
import type { Props } from '@docusaurus/types';
|
|
9
|
+
export default function createClientConfig(props: Props, minify?: boolean): Promise<Configuration>;
|
package/lib/webpack/client.js
CHANGED
|
@@ -7,28 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const
|
|
10
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
13
13
|
const base_1 = require("./base");
|
|
14
14
|
const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
|
|
15
15
|
const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
|
|
16
|
-
function createClientConfig(props, minify = true) {
|
|
17
|
-
var _a;
|
|
18
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
16
|
+
async function createClientConfig(props, minify = true) {
|
|
19
17
|
const isBuilding = process.argv[2] === 'build';
|
|
20
|
-
const config = base_1.createBaseConfig(props, false, minify);
|
|
21
|
-
const clientConfig = webpack_merge_1.default(config, {
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// note: the one in ./dev is modified to work with Docusaurus
|
|
27
|
-
// !isProd && require.resolve('react-dev-utils/hotDevServer.js'),
|
|
28
|
-
!isProd &&
|
|
29
|
-
require.resolve('./react-dev-utils-webpack5/webpackHotDevClient.js'),
|
|
30
|
-
path_1.default.resolve(__dirname, '../client/clientEntry.js'),
|
|
31
|
-
].filter(Boolean),
|
|
18
|
+
const config = await (0, base_1.createBaseConfig)(props, false, minify);
|
|
19
|
+
const clientConfig = (0, webpack_merge_1.default)(config, {
|
|
20
|
+
// useless, disabled on purpose (errors on existing sites with no
|
|
21
|
+
// browserslist config)
|
|
22
|
+
// target: 'browserslist',
|
|
23
|
+
entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
|
|
32
24
|
optimization: {
|
|
33
25
|
// Keep the runtime chunk separated to enable long term caching
|
|
34
26
|
// https://twitter.com/wSokra/status/969679223278505985
|
|
@@ -42,13 +34,14 @@ function createClientConfig(props, minify = true) {
|
|
|
42
34
|
}),
|
|
43
35
|
],
|
|
44
36
|
});
|
|
45
|
-
// When building include the plugin to force terminate building if errors
|
|
37
|
+
// When building, include the plugin to force terminate building if errors
|
|
38
|
+
// happened in the client bundle.
|
|
46
39
|
if (isBuilding) {
|
|
47
|
-
|
|
40
|
+
clientConfig.plugins?.push({
|
|
48
41
|
apply: (compiler) => {
|
|
49
42
|
compiler.hooks.done.tap('client:done', (stats) => {
|
|
50
43
|
if (stats.hasErrors()) {
|
|
51
|
-
|
|
44
|
+
logger_1.default.error('Client bundle compiled with errors therefore further build is impossible.');
|
|
52
45
|
process.exit(1);
|
|
53
46
|
}
|
|
54
47
|
});
|
|
@@ -4,8 +4,18 @@
|
|
|
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 { Compiler } from 'webpack';
|
|
8
|
-
|
|
7
|
+
import { type Compiler } from 'webpack';
|
|
8
|
+
/**
|
|
9
|
+
* We modify webpack runtime to add an extra function called
|
|
10
|
+
* "__webpack_require__.gca" that will allow us to get the corresponding chunk
|
|
11
|
+
* asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
|
|
12
|
+
* For example: if you have a chunk named "my-chunk-name" that will map to
|
|
13
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
14
|
+
* __webpack_require__.gca("my-chunk-name") will return
|
|
15
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
16
|
+
*
|
|
17
|
+
* "gca" stands for "get chunk asset"
|
|
18
|
+
*/
|
|
19
|
+
export default class ChunkAssetPlugin {
|
|
9
20
|
apply(compiler: Compiler): void;
|
|
10
21
|
}
|
|
11
|
-
export default ChunkAssetPlugin;
|
|
@@ -8,16 +8,20 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const webpack_1 = require("webpack");
|
|
10
10
|
const pluginName = 'chunk-asset-plugin';
|
|
11
|
+
/**
|
|
12
|
+
* We modify webpack runtime to add an extra function called
|
|
13
|
+
* "__webpack_require__.gca" that will allow us to get the corresponding chunk
|
|
14
|
+
* asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
|
|
15
|
+
* For example: if you have a chunk named "my-chunk-name" that will map to
|
|
16
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
17
|
+
* __webpack_require__.gca("my-chunk-name") will return
|
|
18
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
19
|
+
*
|
|
20
|
+
* "gca" stands for "get chunk asset"
|
|
21
|
+
*/
|
|
11
22
|
class ChunkAssetPlugin {
|
|
12
23
|
apply(compiler) {
|
|
13
24
|
compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
|
|
14
|
-
/* We modify webpack runtime to add an extra function called "__webpack_require__.gca"
|
|
15
|
-
that will allow us to get the corresponding chunk asset for a webpack chunk.
|
|
16
|
-
Pass it the chunkName or chunkId you want to load.
|
|
17
|
-
For example: if you have a chunk named "my-chunk-name" that will map to "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
18
|
-
__webpack_require__.gca("my-chunk-name") will return "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
19
|
-
"gca" stands for "get chunk asset"
|
|
20
|
-
*/
|
|
21
25
|
mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
|
|
22
26
|
const chunkIdToName = chunk.getChunkMaps(false).name;
|
|
23
27
|
const chunkNameToId = Object.create(null);
|
|
@@ -30,10 +34,13 @@ class ChunkAssetPlugin {
|
|
|
30
34
|
buf.push(
|
|
31
35
|
// If chunkName is passed, we convert it to chunk asset url
|
|
32
36
|
// .p => public path url ("/" or "/baseUrl/")
|
|
33
|
-
// .u(chunkId) =>
|
|
34
|
-
//
|
|
37
|
+
// .u(chunkId) =>
|
|
38
|
+
// chunk asset url ("assets/js/x63b64xd.contentHash.js")
|
|
39
|
+
// not sure where this is documented, but this link was helpful:
|
|
40
|
+
// https://programmer.help/blogs/5d68849083e1a.html
|
|
35
41
|
//
|
|
36
|
-
// Note: __webpack_require__.gca() is called in docusaurus.ts for
|
|
42
|
+
// Note: __webpack_require__.gca() is called in docusaurus.ts for
|
|
43
|
+
// prefetching
|
|
37
44
|
// Note: we previously used jsonpScriptSrc (Webpack 4)
|
|
38
45
|
`__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
|
|
39
46
|
return webpack_1.Template.asString(buf);
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
14
|
* copies of the Software, and to permit persons to whom the Software is
|
|
15
15
|
* furnished to do so, subject to the following conditions:
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in
|
|
17
|
-
* copies or substantial portions of the Software.
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in
|
|
17
|
+
* all copies or substantial portions of the Software.
|
|
18
18
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
19
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
20
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*/
|
|
26
|
-
import { Compiler, Stats } from 'webpack';
|
|
26
|
+
import type { Compiler, Stats } from 'webpack';
|
|
27
27
|
export interface Options {
|
|
28
28
|
/**
|
|
29
29
|
* Write Logs to Console
|
|
@@ -54,7 +54,7 @@ export interface Options {
|
|
|
54
54
|
*/
|
|
55
55
|
cleanOnceBeforeBuildPatterns?: string[];
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
export default class CleanWebpackPlugin {
|
|
58
58
|
private readonly verbose;
|
|
59
59
|
private readonly cleanStaleWebpackAssets;
|
|
60
60
|
private readonly protectWebpackAssets;
|
|
@@ -69,10 +69,10 @@ declare class CleanWebpackPlugin {
|
|
|
69
69
|
*
|
|
70
70
|
* Only happens once.
|
|
71
71
|
*
|
|
72
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
72
|
+
* Warning: It is recommended to initially clean your build directory outside
|
|
73
|
+
* of webpack to minimize unexpected behavior.
|
|
73
74
|
*/
|
|
74
75
|
handleInitial(): void;
|
|
75
76
|
handleDone(stats: Stats): void;
|
|
76
77
|
removeFiles(patterns: string[]): void;
|
|
77
78
|
}
|
|
78
|
-
export default CleanWebpackPlugin;
|
|
@@ -41,7 +41,6 @@ class CleanWebpackPlugin {
|
|
|
41
41
|
}
|
|
42
42
|
apply(compiler) {
|
|
43
43
|
if (!compiler.options.output || !compiler.options.output.path) {
|
|
44
|
-
// eslint-disable-next-line no-console
|
|
45
44
|
console.warn('clean-webpack-plugin: options.output.path not defined. Plugin disabled...');
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
@@ -61,7 +60,8 @@ class CleanWebpackPlugin {
|
|
|
61
60
|
*
|
|
62
61
|
* Only happens once.
|
|
63
62
|
*
|
|
64
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
63
|
+
* Warning: It is recommended to initially clean your build directory outside
|
|
64
|
+
* of webpack to minimize unexpected behavior.
|
|
65
65
|
*/
|
|
66
66
|
handleInitial() {
|
|
67
67
|
if (this.initialClean) {
|
|
@@ -76,7 +76,6 @@ class CleanWebpackPlugin {
|
|
|
76
76
|
*/
|
|
77
77
|
if (stats.hasErrors()) {
|
|
78
78
|
if (this.verbose) {
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
80
79
|
console.warn('clean-webpack-plugin: pausing due to webpack errors');
|
|
81
80
|
}
|
|
82
81
|
return;
|
|
@@ -88,17 +87,13 @@ class CleanWebpackPlugin {
|
|
|
88
87
|
all: false,
|
|
89
88
|
assets: true,
|
|
90
89
|
}).assets || [];
|
|
91
|
-
const assets = statsAssets.map((asset) =>
|
|
92
|
-
return asset.name;
|
|
93
|
-
});
|
|
90
|
+
const assets = statsAssets.map((asset) => asset.name);
|
|
94
91
|
/**
|
|
95
92
|
* Get all files that were in the previous build but not the current
|
|
96
93
|
*
|
|
97
94
|
* (relies on del's cwd: outputPath option)
|
|
98
95
|
*/
|
|
99
|
-
const staleFiles = this.currentAssets.filter((previousAsset) =>
|
|
100
|
-
return assets.includes(previousAsset) === false;
|
|
101
|
-
});
|
|
96
|
+
const staleFiles = this.currentAssets.filter((previousAsset) => assets.includes(previousAsset) === false);
|
|
102
97
|
/**
|
|
103
98
|
* Save assets for next compilation
|
|
104
99
|
*/
|
|
@@ -116,7 +111,7 @@ class CleanWebpackPlugin {
|
|
|
116
111
|
}
|
|
117
112
|
removeFiles(patterns) {
|
|
118
113
|
try {
|
|
119
|
-
const deleted = del_1.sync(patterns, {
|
|
114
|
+
const deleted = (0, del_1.sync)(patterns, {
|
|
120
115
|
force: false,
|
|
121
116
|
// Change context to build directory
|
|
122
117
|
cwd: this.outputPath,
|
|
@@ -135,18 +130,17 @@ class CleanWebpackPlugin {
|
|
|
135
130
|
* https://github.com/webpack/webpack/issues/1904
|
|
136
131
|
* https://github.com/johnagan/clean-webpack-plugin/issues/11
|
|
137
132
|
*/
|
|
138
|
-
// eslint-disable-next-line no-console
|
|
139
133
|
console.warn(`clean-webpack-plugin: removed ${filename}`);
|
|
140
134
|
});
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
|
-
catch (
|
|
144
|
-
const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(
|
|
137
|
+
catch (err) {
|
|
138
|
+
const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(err.message);
|
|
145
139
|
if (needsForce) {
|
|
146
140
|
const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the "dangerouslyAllowCleanPatternsOutsideProject" option.';
|
|
147
141
|
throw new Error(message);
|
|
148
142
|
}
|
|
149
|
-
throw
|
|
143
|
+
throw err;
|
|
150
144
|
}
|
|
151
145
|
}
|
|
152
146
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import WebpackBar from 'webpackbar';
|
|
8
|
-
import { Compiler } from 'webpack';
|
|
8
|
+
import type { Compiler } from 'webpack';
|
|
9
9
|
export default class LogPlugin extends WebpackBar {
|
|
10
10
|
apply(compiler: Compiler): void;
|
|
11
11
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
2
|
/**
|
|
5
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
4
|
*
|
|
7
5
|
* This source code is licensed under the MIT license found in the
|
|
8
6
|
* LICENSE file in the root directory of this source tree.
|
|
9
7
|
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
10
|
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
11
|
-
|
|
12
|
-
const formatWebpackMessages_1 = tslib_1.__importDefault(require("../react-dev-utils-webpack5/formatWebpackMessages"));
|
|
11
|
+
const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
|
|
13
12
|
function showError(arr) {
|
|
14
13
|
console.log(`\n\n${arr.join('\n')}`);
|
|
15
14
|
}
|
|
@@ -23,7 +22,7 @@ class LogPlugin extends webpackbar_1.default {
|
|
|
23
22
|
// TODO do we really want to keep this legacy logic?
|
|
24
23
|
// let's wait and see how the react-dev-utils support Webpack5
|
|
25
24
|
// we probably want to print the error stacktraces here
|
|
26
|
-
const messages = formatWebpackMessages_1.default(errorsWarnings);
|
|
25
|
+
const messages = (0, formatWebpackMessages_1.default)(errorsWarnings);
|
|
27
26
|
if (messages.errors.length) {
|
|
28
27
|
showError(messages.errors);
|
|
29
28
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
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 { Compiler } from 'webpack';
|
|
7
|
+
import type { Compiler } from 'webpack';
|
|
8
8
|
interface WaitPluginOptions {
|
|
9
9
|
filepath: string;
|
|
10
10
|
}
|
|
@@ -20,7 +20,7 @@ class WaitPlugin {
|
|
|
20
20
|
// To prevent 'waitFile' error on waiting non-existing directory
|
|
21
21
|
fs_extra_1.default.ensureDir(path_1.default.dirname(this.filepath), {}, () => {
|
|
22
22
|
// Wait until file exist
|
|
23
|
-
wait_on_1.default({
|
|
23
|
+
(0, wait_on_1.default)({
|
|
24
24
|
resources: [this.filepath],
|
|
25
25
|
interval: 300,
|
|
26
26
|
})
|
package/lib/webpack/server.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
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 { Configuration } from 'webpack';
|
|
8
|
-
import { Props } from '@docusaurus/types';
|
|
7
|
+
import type { Configuration } from 'webpack';
|
|
8
|
+
import type { Props } from '@docusaurus/types';
|
|
9
9
|
export default function createServerConfig({ props, onLinksCollected, }: {
|
|
10
10
|
props: Props;
|
|
11
11
|
onLinksCollected?: (staticPagePath: string, links: string[]) => void;
|
|
12
|
-
}): Configuration
|
|
12
|
+
}): Promise<Configuration>;
|
package/lib/webpack/server.js
CHANGED
|
@@ -12,12 +12,12 @@ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
|
12
12
|
const base_1 = require("./base");
|
|
13
13
|
const WaitPlugin_1 = tslib_1.__importDefault(require("./plugins/WaitPlugin"));
|
|
14
14
|
const LogPlugin_1 = tslib_1.__importDefault(require("./plugins/LogPlugin"));
|
|
15
|
-
const
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
// Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
|
|
17
17
|
const static_site_generator_webpack_plugin_1 = tslib_1.__importDefault(require("@slorber/static-site-generator-webpack-plugin"));
|
|
18
|
-
function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
18
|
+
async function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
19
19
|
const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
|
|
20
|
-
const config = base_1.createBaseConfig(props, true);
|
|
20
|
+
const config = await (0, base_1.createBaseConfig)(props, true);
|
|
21
21
|
const routesLocation = {};
|
|
22
22
|
// Array of paths to be rendered. Relative to output directory
|
|
23
23
|
const ssgPaths = routesPaths.map((str) => {
|
|
@@ -25,8 +25,8 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
|
25
25
|
routesLocation[ssgPath] = str;
|
|
26
26
|
return ssgPath;
|
|
27
27
|
});
|
|
28
|
-
const serverConfig = webpack_merge_1.default(config, {
|
|
29
|
-
target: `node${
|
|
28
|
+
const serverConfig = (0, webpack_merge_1.default)(config, {
|
|
29
|
+
target: `node${utils_1.NODE_MAJOR_VERSION}.${utils_1.NODE_MINOR_VERSION}`,
|
|
30
30
|
entry: {
|
|
31
31
|
main: path_1.default.resolve(__dirname, '../client/serverEntry.js'),
|
|
32
32
|
},
|
|
@@ -57,9 +57,10 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
|
57
57
|
},
|
|
58
58
|
paths: ssgPaths,
|
|
59
59
|
preferFoldersOutput: trailingSlash,
|
|
60
|
-
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
61
|
-
//
|
|
62
|
-
//
|
|
60
|
+
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
61
|
+
// __filename, and this plugin will throw. not sure the __filename value
|
|
62
|
+
// has any importance for this plugin, just using an empty string to
|
|
63
|
+
// avoid the error. See https://github.com/facebook/docusaurus/issues/4922
|
|
63
64
|
globals: { __filename: '' },
|
|
64
65
|
}),
|
|
65
66
|
// Show compilation progress bar.
|