@docusaurus/core 0.0.0-6080 → 0.0.0-6082
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/babel/preset.d.ts +2 -2
- package/lib/babel/preset.js +10 -71
- package/lib/commands/build.js +9 -9
- package/lib/commands/start/webpack.js +5 -4
- package/lib/commands/writeHeadingIds.js +1 -2
- package/lib/commands/writeTranslations.js +6 -6
- package/lib/server/site.js +7 -1
- package/lib/server/translations/translationsExtractor.d.ts +5 -11
- package/lib/server/translations/translationsExtractor.js +8 -196
- package/lib/webpack/base.js +9 -8
- package/lib/webpack/client.js +6 -6
- package/lib/webpack/configure.d.ts +1 -2
- package/lib/webpack/configure.js +4 -5
- package/lib/webpack/plugins/ForceTerminatePlugin.js +2 -2
- package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.d.ts +2 -3
- package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.js +4 -4
- package/lib/webpack/server.js +5 -3
- package/lib/{server/utils.d.ts → webpack/utils/getHttpsConfig.d.ts} +4 -2
- package/lib/webpack/utils/getHttpsConfig.js +60 -0
- package/package.json +12 -37
- package/lib/faster.d.ts +0 -10
- package/lib/faster.js +0 -29
- package/lib/server/utils.js +0 -20
- package/lib/webpack/currentBundler.d.ts +0 -24
- package/lib/webpack/currentBundler.js +0 -42
- package/lib/webpack/minification.d.ts +0 -12
- package/lib/webpack/minification.js +0 -106
- package/lib/webpack/utils.d.ts +0 -38
- package/lib/webpack/utils.js +0 -227
package/lib/webpack/configure.js
CHANGED
|
@@ -11,16 +11,15 @@ exports.applyConfigureWebpack = applyConfigureWebpack;
|
|
|
11
11
|
exports.applyConfigurePostCss = applyConfigurePostCss;
|
|
12
12
|
exports.executePluginsConfigureWebpack = executePluginsConfigureWebpack;
|
|
13
13
|
const webpack_merge_1 = require("webpack-merge");
|
|
14
|
-
const
|
|
15
|
-
const currentBundler_1 = require("./currentBundler");
|
|
14
|
+
const bundler_1 = require("@docusaurus/bundler");
|
|
16
15
|
/**
|
|
17
16
|
* Creates convenient utils to inject into the configureWebpack() lifecycle
|
|
18
17
|
* @param config the Docusaurus config
|
|
19
18
|
*/
|
|
20
19
|
async function createConfigureWebpackUtils({ siteConfig, }) {
|
|
21
|
-
const currentBundler = await (0,
|
|
22
|
-
const getStyleLoaders = await (0,
|
|
23
|
-
const getJSLoader = await (0,
|
|
20
|
+
const currentBundler = await (0, bundler_1.getCurrentBundler)({ siteConfig });
|
|
21
|
+
const getStyleLoaders = await (0, bundler_1.createStyleLoadersFactory)({ currentBundler });
|
|
22
|
+
const getJSLoader = await (0, bundler_1.createJsLoaderFactory)({ siteConfig });
|
|
24
23
|
return {
|
|
25
24
|
currentBundler,
|
|
26
25
|
getStyleLoaders,
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
+
const bundler_1 = require("@docusaurus/bundler");
|
|
10
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
12
|
// When building, include the plugin to force terminate building if errors
|
|
13
13
|
// happened in the client bundle.
|
|
14
14
|
class ForceTerminatePlugin {
|
|
@@ -16,7 +16,7 @@ class ForceTerminatePlugin {
|
|
|
16
16
|
compiler.hooks.done.tap('client:done', (stats) => {
|
|
17
17
|
if (stats.hasErrors()) {
|
|
18
18
|
const errorsWarnings = stats.toJson('errors-warnings');
|
|
19
|
-
logger_1.default.error(`Client bundle compiled with errors therefore further build is impossible.\n${(0,
|
|
19
|
+
logger_1.default.error(`Client bundle compiled with errors therefore further build is impossible.\n${(0, bundler_1.formatStatsErrorMessage)(errorsWarnings)}`);
|
|
20
20
|
process.exit(1);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
@@ -4,9 +4,8 @@
|
|
|
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 type {
|
|
7
|
+
import type { Props } from '@docusaurus/types';
|
|
8
8
|
import type { WebpackPluginInstance } from 'webpack';
|
|
9
|
-
export declare function createStaticDirectoriesCopyPlugin({ props,
|
|
9
|
+
export declare function createStaticDirectoriesCopyPlugin({ props, }: {
|
|
10
10
|
props: Props;
|
|
11
|
-
currentBundler: CurrentBundler;
|
|
12
11
|
}): Promise<WebpackPluginInstance | undefined>;
|
|
@@ -10,10 +10,10 @@ exports.createStaticDirectoriesCopyPlugin = createStaticDirectoriesCopyPlugin;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const
|
|
14
|
-
async function createStaticDirectoriesCopyPlugin({ props,
|
|
15
|
-
const CopyPlugin = await (0,
|
|
16
|
-
currentBundler,
|
|
13
|
+
const bundler_1 = require("@docusaurus/bundler");
|
|
14
|
+
async function createStaticDirectoriesCopyPlugin({ props, }) {
|
|
15
|
+
const CopyPlugin = await (0, bundler_1.getCopyPlugin)({
|
|
16
|
+
currentBundler: props.currentBundler,
|
|
17
17
|
});
|
|
18
18
|
const { outDir, siteDir, siteConfig: { staticDirectories: staticDirectoriesOption }, } = props;
|
|
19
19
|
// The staticDirectories option can contain empty directories, or non-existent
|
package/lib/webpack/server.js
CHANGED
|
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
|
|
|
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 utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const
|
|
14
|
+
const bundler_1 = require("@docusaurus/bundler");
|
|
15
15
|
const base_1 = require("./base");
|
|
16
16
|
async function createServerConfig({ props, configureWebpackUtils, }) {
|
|
17
17
|
const baseConfig = await (0, base_1.createBaseConfig)({
|
|
@@ -21,6 +21,9 @@ async function createServerConfig({ props, configureWebpackUtils, }) {
|
|
|
21
21
|
faster: props.siteConfig.future.experimental_faster,
|
|
22
22
|
configureWebpackUtils,
|
|
23
23
|
});
|
|
24
|
+
const ProgressBarPlugin = await (0, bundler_1.getProgressBarPlugin)({
|
|
25
|
+
currentBundler: props.currentBundler,
|
|
26
|
+
});
|
|
24
27
|
const outputFilename = 'server.bundle.js';
|
|
25
28
|
const outputDir = path_1.default.join(props.outDir, '__server');
|
|
26
29
|
const serverBundlePath = path_1.default.join(outputDir, outputFilename);
|
|
@@ -35,8 +38,7 @@ async function createServerConfig({ props, configureWebpackUtils, }) {
|
|
|
35
38
|
libraryTarget: 'commonjs2',
|
|
36
39
|
},
|
|
37
40
|
plugins: [
|
|
38
|
-
|
|
39
|
-
new webpackbar_1.default({
|
|
41
|
+
new ProgressBarPlugin({
|
|
40
42
|
name: 'Server',
|
|
41
43
|
color: 'yellow',
|
|
42
44
|
}),
|
|
@@ -4,5 +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
|
-
|
|
8
|
-
|
|
7
|
+
export default function getHttpsConfig(): Promise<boolean | {
|
|
8
|
+
cert: Buffer;
|
|
9
|
+
key: Buffer;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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.default = getHttpsConfig;
|
|
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
|
+
// Ensure the certificate and key provided are valid and if not
|
|
16
|
+
// throw an easy to debug error
|
|
17
|
+
function validateKeyAndCerts({ cert, key, keyFile, crtFile, }) {
|
|
18
|
+
let encrypted;
|
|
19
|
+
try {
|
|
20
|
+
// publicEncrypt will throw an error with an invalid cert
|
|
21
|
+
encrypted = crypto_1.default.publicEncrypt(cert, Buffer.from('test'));
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
logger_1.default.error `The certificate path=${crtFile} is invalid.`;
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
// privateDecrypt will throw an error with an invalid key
|
|
29
|
+
crypto_1.default.privateDecrypt(key, encrypted);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
logger_1.default.error `The certificate key path=${keyFile} is invalid.`;
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Read file and throw an error if it doesn't exist
|
|
37
|
+
async function readEnvFile(file, type) {
|
|
38
|
+
if (!(await fs_extra_1.default.pathExists(file))) {
|
|
39
|
+
throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
|
|
40
|
+
}
|
|
41
|
+
return fs_extra_1.default.readFile(file);
|
|
42
|
+
}
|
|
43
|
+
// Get the https config
|
|
44
|
+
// Return cert files if provided in env, otherwise just true or false
|
|
45
|
+
async function getHttpsConfig() {
|
|
46
|
+
const appDirectory = await fs_extra_1.default.realpath(process.cwd());
|
|
47
|
+
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
|
|
48
|
+
const isHttps = HTTPS === 'true';
|
|
49
|
+
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
|
|
50
|
+
const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
|
|
51
|
+
const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
|
|
52
|
+
const config = {
|
|
53
|
+
cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
|
|
54
|
+
key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
|
|
55
|
+
};
|
|
56
|
+
validateKeyAndCerts({ ...config, keyFile, crtFile });
|
|
57
|
+
return config;
|
|
58
|
+
}
|
|
59
|
+
return isHttps;
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-6082",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,54 +33,32 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@babel
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@babel/runtime": "^7.22.6",
|
|
44
|
-
"@babel/runtime-corejs3": "^7.22.6",
|
|
45
|
-
"@babel/traverse": "^7.22.8",
|
|
46
|
-
"@docusaurus/cssnano-preset": "0.0.0-6080",
|
|
47
|
-
"@docusaurus/logger": "0.0.0-6080",
|
|
48
|
-
"@docusaurus/mdx-loader": "0.0.0-6080",
|
|
49
|
-
"@docusaurus/utils": "0.0.0-6080",
|
|
50
|
-
"@docusaurus/utils-common": "0.0.0-6080",
|
|
51
|
-
"@docusaurus/utils-validation": "0.0.0-6080",
|
|
52
|
-
"autoprefixer": "^10.4.14",
|
|
53
|
-
"babel-loader": "^9.1.3",
|
|
54
|
-
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
36
|
+
"@docusaurus/babel": "0.0.0-6082",
|
|
37
|
+
"@docusaurus/bundler": "0.0.0-6082",
|
|
38
|
+
"@docusaurus/logger": "0.0.0-6082",
|
|
39
|
+
"@docusaurus/mdx-loader": "0.0.0-6082",
|
|
40
|
+
"@docusaurus/utils": "0.0.0-6082",
|
|
41
|
+
"@docusaurus/utils-common": "0.0.0-6082",
|
|
42
|
+
"@docusaurus/utils-validation": "0.0.0-6082",
|
|
55
43
|
"boxen": "^6.2.1",
|
|
56
44
|
"chalk": "^4.1.2",
|
|
57
45
|
"chokidar": "^3.5.3",
|
|
58
|
-
"clean-css": "^5.3.2",
|
|
59
46
|
"cli-table3": "^0.6.3",
|
|
60
47
|
"combine-promises": "^1.1.0",
|
|
61
48
|
"commander": "^5.1.0",
|
|
62
|
-
"copy-webpack-plugin": "^11.0.0",
|
|
63
49
|
"core-js": "^3.31.1",
|
|
64
|
-
"css-loader": "^6.8.1",
|
|
65
|
-
"css-minimizer-webpack-plugin": "^5.0.1",
|
|
66
|
-
"cssnano": "^6.1.2",
|
|
67
50
|
"del": "^6.1.1",
|
|
68
51
|
"detect-port": "^1.5.1",
|
|
69
52
|
"escape-html": "^1.0.3",
|
|
70
53
|
"eta": "^2.2.0",
|
|
71
54
|
"eval": "^0.1.8",
|
|
72
|
-
"file-loader": "^6.2.0",
|
|
73
55
|
"fs-extra": "^11.1.1",
|
|
74
56
|
"html-minifier-terser": "^7.2.0",
|
|
75
57
|
"html-tags": "^3.3.1",
|
|
76
58
|
"html-webpack-plugin": "^5.5.3",
|
|
77
59
|
"leven": "^3.1.0",
|
|
78
60
|
"lodash": "^4.17.21",
|
|
79
|
-
"mini-css-extract-plugin": "^2.7.6",
|
|
80
|
-
"null-loader": "^4.0.1",
|
|
81
61
|
"p-map": "^4.0.0",
|
|
82
|
-
"postcss": "^8.4.26",
|
|
83
|
-
"postcss-loader": "^7.3.3",
|
|
84
62
|
"prompts": "^2.4.2",
|
|
85
63
|
"react-dev-utils": "^12.0.1",
|
|
86
64
|
"react-helmet-async": "^1.3.0",
|
|
@@ -93,19 +71,16 @@
|
|
|
93
71
|
"semver": "^7.5.4",
|
|
94
72
|
"serve-handler": "npm:@docusaurus/serve-handler@6.2.0",
|
|
95
73
|
"shelljs": "^0.8.5",
|
|
96
|
-
"terser-webpack-plugin": "^5.3.10",
|
|
97
74
|
"tslib": "^2.6.0",
|
|
98
75
|
"update-notifier": "^6.0.2",
|
|
99
|
-
"url-loader": "^4.1.1",
|
|
100
76
|
"webpack": "^5.88.1",
|
|
101
77
|
"webpack-bundle-analyzer": "^4.9.0",
|
|
102
78
|
"webpack-dev-server": "^4.15.1",
|
|
103
|
-
"webpack-merge": "^5.9.0"
|
|
104
|
-
"webpackbar": "^5.0.2"
|
|
79
|
+
"webpack-merge": "^5.9.0"
|
|
105
80
|
},
|
|
106
81
|
"devDependencies": {
|
|
107
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
108
|
-
"@docusaurus/types": "0.0.0-
|
|
82
|
+
"@docusaurus/module-type-aliases": "0.0.0-6082",
|
|
83
|
+
"@docusaurus/types": "0.0.0-6082",
|
|
109
84
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
110
85
|
"@types/detect-port": "^1.3.3",
|
|
111
86
|
"@types/react-dom": "^18.2.7",
|
|
@@ -132,5 +107,5 @@
|
|
|
132
107
|
"engines": {
|
|
133
108
|
"node": ">=18.0"
|
|
134
109
|
},
|
|
135
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "bbf50dffd0ec70f522b74e73406e4d18037d77f2"
|
|
136
111
|
}
|
package/lib/faster.d.ts
DELETED
|
@@ -1,10 +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 { ConfigureWebpackUtils } from '@docusaurus/types';
|
|
8
|
-
import type { MinimizerOptions, CustomOptions } from 'terser-webpack-plugin';
|
|
9
|
-
export declare function importSwcJsLoaderFactory(): Promise<ConfigureWebpackUtils['getJSLoader']>;
|
|
10
|
-
export declare function importSwcJsMinifierOptions(): Promise<MinimizerOptions<CustomOptions>>;
|
package/lib/faster.js
DELETED
|
@@ -1,29 +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.importSwcJsLoaderFactory = importSwcJsLoaderFactory;
|
|
10
|
-
exports.importSwcJsMinifierOptions = importSwcJsMinifierOptions;
|
|
11
|
-
async function importFaster() {
|
|
12
|
-
return import('@docusaurus/faster');
|
|
13
|
-
}
|
|
14
|
-
async function ensureFaster() {
|
|
15
|
-
try {
|
|
16
|
-
return await importFaster();
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
throw new Error('Your Docusaurus site need to add the @docusaurus/faster package as a dependency.', { cause: error });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async function importSwcJsLoaderFactory() {
|
|
23
|
-
const faster = await ensureFaster();
|
|
24
|
-
return faster.getSwcJsLoaderFactory;
|
|
25
|
-
}
|
|
26
|
-
async function importSwcJsMinifierOptions() {
|
|
27
|
-
const faster = await ensureFaster();
|
|
28
|
-
return faster.getSwcJsMinifierOptions();
|
|
29
|
-
}
|
package/lib/server/utils.js
DELETED
|
@@ -1,20 +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.safeGlobby = safeGlobby;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const utils_1 = require("@docusaurus/utils");
|
|
13
|
-
// Globby that fix Windows path patterns
|
|
14
|
-
// See https://github.com/facebook/docusaurus/pull/4222#issuecomment-795517329
|
|
15
|
-
async function safeGlobby(patterns, options) {
|
|
16
|
-
// Required for Windows support, as paths using \ should not be used by globby
|
|
17
|
-
// (also using the windows hard drive prefix like c: is not a good idea)
|
|
18
|
-
const globPaths = patterns.map((dirPath) => (0, utils_1.posixPath)(path_1.default.relative(process.cwd(), dirPath)));
|
|
19
|
-
return (0, utils_1.Globby)(globPaths, options);
|
|
20
|
-
}
|
|
@@ -1,24 +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 MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
8
|
-
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
9
|
-
import type { CurrentBundler, DocusaurusConfig } from '@docusaurus/types';
|
|
10
|
-
type SiteConfigSlice = {
|
|
11
|
-
future: {
|
|
12
|
-
experimental_faster: Pick<DocusaurusConfig['future']['experimental_faster'], 'rspackBundler'>;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare function getCurrentBundler({ siteConfig, }: {
|
|
16
|
-
siteConfig: SiteConfigSlice;
|
|
17
|
-
}): Promise<CurrentBundler>;
|
|
18
|
-
export declare function getCSSExtractPlugin({ currentBundler, }: {
|
|
19
|
-
currentBundler: CurrentBundler;
|
|
20
|
-
}): Promise<typeof MiniCssExtractPlugin>;
|
|
21
|
-
export declare function getCopyPlugin({ currentBundler, }: {
|
|
22
|
-
currentBundler: CurrentBundler;
|
|
23
|
-
}): Promise<typeof CopyWebpackPlugin>;
|
|
24
|
-
export {};
|
|
@@ -1,42 +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.getCurrentBundler = getCurrentBundler;
|
|
10
|
-
exports.getCSSExtractPlugin = getCSSExtractPlugin;
|
|
11
|
-
exports.getCopyPlugin = getCopyPlugin;
|
|
12
|
-
const tslib_1 = require("tslib");
|
|
13
|
-
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
14
|
-
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
15
|
-
const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
|
|
16
|
-
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
17
|
-
function isRspack(siteConfig) {
|
|
18
|
-
return siteConfig.future.experimental_faster.rspackBundler;
|
|
19
|
-
}
|
|
20
|
-
async function getCurrentBundler({ siteConfig, }) {
|
|
21
|
-
if (isRspack(siteConfig)) {
|
|
22
|
-
// TODO add support for Rspack
|
|
23
|
-
logger_1.default.error('Rspack bundler is not supported yet, will use Webpack instead');
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
name: 'webpack',
|
|
27
|
-
instance: webpack_1.default,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
async function getCSSExtractPlugin({ currentBundler, }) {
|
|
31
|
-
if (currentBundler.name === 'rspack') {
|
|
32
|
-
throw new Error('Rspack bundler is not supported yet');
|
|
33
|
-
}
|
|
34
|
-
return mini_css_extract_plugin_1.default;
|
|
35
|
-
}
|
|
36
|
-
async function getCopyPlugin({ currentBundler, }) {
|
|
37
|
-
if (currentBundler.name === 'rspack') {
|
|
38
|
-
throw new Error('Rspack bundler is not supported yet');
|
|
39
|
-
}
|
|
40
|
-
// https://github.com/webpack-contrib/copy-webpack-plugin
|
|
41
|
-
return copy_webpack_plugin_1.default;
|
|
42
|
-
}
|
|
@@ -1,12 +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 { WebpackPluginInstance } from 'webpack';
|
|
8
|
-
import type { FasterConfig } from '@docusaurus/types';
|
|
9
|
-
export type MinimizersConfig = {
|
|
10
|
-
faster: Pick<FasterConfig, 'swcJsMinimizer'>;
|
|
11
|
-
};
|
|
12
|
-
export declare function getMinimizers(params: MinimizersConfig): Promise<WebpackPluginInstance[]>;
|
|
@@ -1,106 +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.getMinimizers = getMinimizers;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const terser_webpack_plugin_1 = tslib_1.__importDefault(require("terser-webpack-plugin"));
|
|
12
|
-
const css_minimizer_webpack_plugin_1 = tslib_1.__importDefault(require("css-minimizer-webpack-plugin"));
|
|
13
|
-
const faster_1 = require("../faster");
|
|
14
|
-
// See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
|
|
15
|
-
function getTerserParallel() {
|
|
16
|
-
let terserParallel = true;
|
|
17
|
-
if (process.env.TERSER_PARALLEL === 'false') {
|
|
18
|
-
terserParallel = false;
|
|
19
|
-
}
|
|
20
|
-
else if (process.env.TERSER_PARALLEL &&
|
|
21
|
-
parseInt(process.env.TERSER_PARALLEL, 10) > 0) {
|
|
22
|
-
terserParallel = parseInt(process.env.TERSER_PARALLEL, 10);
|
|
23
|
-
}
|
|
24
|
-
return terserParallel;
|
|
25
|
-
}
|
|
26
|
-
async function getJsMinimizer({ faster }) {
|
|
27
|
-
if (faster.swcJsMinimizer) {
|
|
28
|
-
const terserOptions = await (0, faster_1.importSwcJsMinifierOptions)();
|
|
29
|
-
return new terser_webpack_plugin_1.default({
|
|
30
|
-
parallel: getTerserParallel(),
|
|
31
|
-
minify: terser_webpack_plugin_1.default.swcMinify,
|
|
32
|
-
terserOptions,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return new terser_webpack_plugin_1.default({
|
|
36
|
-
parallel: getTerserParallel(),
|
|
37
|
-
terserOptions: {
|
|
38
|
-
parse: {
|
|
39
|
-
// We want uglify-js to parse ecma 8 code. However, we don't want it
|
|
40
|
-
// to apply any minification steps that turns valid ecma 5 code
|
|
41
|
-
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
42
|
-
// sections only apply transformations that are ecma 5 safe
|
|
43
|
-
// https://github.com/facebook/create-react-app/pull/4234
|
|
44
|
-
ecma: 2020,
|
|
45
|
-
},
|
|
46
|
-
compress: {
|
|
47
|
-
ecma: 5,
|
|
48
|
-
},
|
|
49
|
-
mangle: {
|
|
50
|
-
safari10: true,
|
|
51
|
-
},
|
|
52
|
-
output: {
|
|
53
|
-
ecma: 5,
|
|
54
|
-
comments: false,
|
|
55
|
-
// Turned on because emoji and regex is not minified properly using
|
|
56
|
-
// default. See https://github.com/facebook/create-react-app/issues/2488
|
|
57
|
-
ascii_only: true,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function getAdvancedCssMinifier() {
|
|
63
|
-
// Using the array syntax to add 2 minimizers
|
|
64
|
-
// see https://github.com/webpack-contrib/css-minimizer-webpack-plugin#array
|
|
65
|
-
return new css_minimizer_webpack_plugin_1.default({
|
|
66
|
-
minimizerOptions: [
|
|
67
|
-
// CssNano options
|
|
68
|
-
{
|
|
69
|
-
preset: require.resolve('@docusaurus/cssnano-preset'),
|
|
70
|
-
},
|
|
71
|
-
// CleanCss options
|
|
72
|
-
{
|
|
73
|
-
inline: false,
|
|
74
|
-
level: {
|
|
75
|
-
1: {
|
|
76
|
-
all: false,
|
|
77
|
-
removeWhitespace: true,
|
|
78
|
-
},
|
|
79
|
-
2: {
|
|
80
|
-
all: true,
|
|
81
|
-
restructureRules: true,
|
|
82
|
-
removeUnusedAtRules: false,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
minify: [
|
|
88
|
-
css_minimizer_webpack_plugin_1.default.cssnanoMinify,
|
|
89
|
-
css_minimizer_webpack_plugin_1.default.cleanCssMinify,
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function getCssMinimizer() {
|
|
94
|
-
// This is an historical env variable to opt-out of the advanced minifier
|
|
95
|
-
// Sometimes there's a bug in it and people are happy to disable it
|
|
96
|
-
const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true';
|
|
97
|
-
if (useSimpleCssMinifier) {
|
|
98
|
-
return new css_minimizer_webpack_plugin_1.default();
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return getAdvancedCssMinifier();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async function getMinimizers(params) {
|
|
105
|
-
return Promise.all([getJsMinimizer(params), getCssMinimizer()]);
|
|
106
|
-
}
|
package/lib/webpack/utils.d.ts
DELETED
|
@@ -1,38 +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 webpack, { type Configuration } from 'webpack';
|
|
8
|
-
import type { ConfigureWebpackUtils, CurrentBundler, DocusaurusConfig } from '@docusaurus/types';
|
|
9
|
-
import type { TransformOptions } from '@babel/core';
|
|
10
|
-
export declare function formatStatsErrorMessage(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): string | undefined;
|
|
11
|
-
export declare function printStatsWarnings(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): void;
|
|
12
|
-
export declare function createStyleLoadersFactory({ currentBundler, }: {
|
|
13
|
-
currentBundler: CurrentBundler;
|
|
14
|
-
}): Promise<ConfigureWebpackUtils['getStyleLoaders']>;
|
|
15
|
-
export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
|
|
16
|
-
export declare function getBabelOptions({ isServer, babelOptions, }?: {
|
|
17
|
-
isServer?: boolean;
|
|
18
|
-
babelOptions?: TransformOptions | string;
|
|
19
|
-
}): TransformOptions;
|
|
20
|
-
export declare function createJsLoaderFactory({ siteConfig, }: {
|
|
21
|
-
siteConfig: {
|
|
22
|
-
webpack?: DocusaurusConfig['webpack'];
|
|
23
|
-
future?: {
|
|
24
|
-
experimental_faster: DocusaurusConfig['future']['experimental_faster'];
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}): Promise<ConfigureWebpackUtils['getJSLoader']>;
|
|
28
|
-
declare global {
|
|
29
|
-
interface Error {
|
|
30
|
-
/** @see https://webpack.js.org/api/node/#error-handling */
|
|
31
|
-
details: unknown;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export declare function compile(config: Configuration[]): Promise<webpack.MultiStats>;
|
|
35
|
-
export declare function getHttpsConfig(): Promise<boolean | {
|
|
36
|
-
cert: Buffer;
|
|
37
|
-
key: Buffer;
|
|
38
|
-
}>;
|