@docusaurus/core 0.0.0-6072 → 0.0.0-6079
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/commands/build.js +9 -8
- package/lib/commands/start/webpack.js +8 -3
- package/lib/server/configValidation.js +3 -0
- package/lib/server/translations/translationsExtractor.js +1 -1
- package/lib/webpack/base.d.ts +3 -2
- package/lib/webpack/base.js +8 -5
- package/lib/webpack/client.d.ts +5 -3
- package/lib/webpack/client.js +17 -6
- package/lib/webpack/configure.d.ts +6 -5
- package/lib/webpack/configure.js +11 -6
- package/lib/webpack/currentBundler.d.ts +24 -0
- package/lib/webpack/currentBundler.js +42 -0
- package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.d.ts +5 -4
- package/lib/webpack/plugins/StaticDirectoriesCopyPlugin.js +6 -3
- package/lib/webpack/server.d.ts +3 -2
- package/lib/webpack/server.js +2 -2
- package/lib/webpack/utils.d.ts +5 -5
- package/lib/webpack/utils.js +54 -52
- package/package.json +10 -10
package/lib/commands/build.js
CHANGED
|
@@ -99,14 +99,17 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
|
|
|
99
99
|
const { props } = site;
|
|
100
100
|
const { outDir, plugins, siteConfig } = props;
|
|
101
101
|
const router = siteConfig.future.experimental_router;
|
|
102
|
+
const configureWebpackUtils = await (0, configure_1.createConfigureWebpackUtils)({ siteConfig });
|
|
102
103
|
// We can build the 2 configs in parallel
|
|
103
104
|
const [{ clientConfig, clientManifestPath }, { serverConfig, serverBundlePath }] = await logger_1.PerfLogger.async('Creating webpack configs', () => Promise.all([
|
|
104
105
|
getBuildClientConfig({
|
|
105
106
|
props,
|
|
106
107
|
cliOptions,
|
|
108
|
+
configureWebpackUtils,
|
|
107
109
|
}),
|
|
108
110
|
getBuildServerConfig({
|
|
109
111
|
props,
|
|
112
|
+
configureWebpackUtils,
|
|
110
113
|
}),
|
|
111
114
|
]));
|
|
112
115
|
// Run webpack to build JS bundle (client) and static html files (server).
|
|
@@ -189,12 +192,13 @@ async function executeBrokenLinksCheck({ props: { routes, siteConfig: { onBroken
|
|
|
189
192
|
onBrokenAnchors,
|
|
190
193
|
});
|
|
191
194
|
}
|
|
192
|
-
async function getBuildClientConfig({ props, cliOptions, }) {
|
|
195
|
+
async function getBuildClientConfig({ props, cliOptions, configureWebpackUtils, }) {
|
|
193
196
|
const { plugins } = props;
|
|
194
197
|
const result = await (0, client_1.createBuildClientConfig)({
|
|
195
198
|
props,
|
|
196
199
|
minify: cliOptions.minify ?? true,
|
|
197
200
|
faster: props.siteConfig.future.experimental_faster,
|
|
201
|
+
configureWebpackUtils,
|
|
198
202
|
bundleAnalyzer: cliOptions.bundleAnalyzer ?? false,
|
|
199
203
|
});
|
|
200
204
|
let { config } = result;
|
|
@@ -202,25 +206,22 @@ async function getBuildClientConfig({ props, cliOptions, }) {
|
|
|
202
206
|
plugins,
|
|
203
207
|
config,
|
|
204
208
|
isServer: false,
|
|
205
|
-
|
|
206
|
-
siteConfig: props.siteConfig,
|
|
207
|
-
}),
|
|
209
|
+
configureWebpackUtils,
|
|
208
210
|
});
|
|
209
211
|
return { clientConfig: config, clientManifestPath: result.clientManifestPath };
|
|
210
212
|
}
|
|
211
|
-
async function getBuildServerConfig({ props }) {
|
|
213
|
+
async function getBuildServerConfig({ props, configureWebpackUtils, }) {
|
|
212
214
|
const { plugins } = props;
|
|
213
215
|
const result = await (0, server_1.default)({
|
|
214
216
|
props,
|
|
217
|
+
configureWebpackUtils,
|
|
215
218
|
});
|
|
216
219
|
let { config } = result;
|
|
217
220
|
config = (0, configure_1.executePluginsConfigureWebpack)({
|
|
218
221
|
plugins,
|
|
219
222
|
config,
|
|
220
223
|
isServer: true,
|
|
221
|
-
|
|
222
|
-
siteConfig: props.siteConfig,
|
|
223
|
-
}),
|
|
224
|
+
configureWebpackUtils,
|
|
224
225
|
});
|
|
225
226
|
return { serverConfig: config, serverBundlePath: result.serverBundlePath };
|
|
226
227
|
}
|
|
@@ -97,27 +97,32 @@ async function createDevServerConfig({ cliOptions, props, host, port, }) {
|
|
|
97
97
|
},
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
async function getStartClientConfig({ props, minify, poll, }) {
|
|
101
|
-
const { plugins
|
|
100
|
+
async function getStartClientConfig({ props, minify, poll, configureWebpackUtils, }) {
|
|
101
|
+
const { plugins } = props;
|
|
102
102
|
let { clientConfig: config } = await (0, client_1.createStartClientConfig)({
|
|
103
103
|
props,
|
|
104
104
|
minify,
|
|
105
105
|
faster: props.siteConfig.future.experimental_faster,
|
|
106
106
|
poll,
|
|
107
|
+
configureWebpackUtils,
|
|
107
108
|
});
|
|
108
109
|
config = (0, configure_1.executePluginsConfigureWebpack)({
|
|
109
110
|
plugins,
|
|
110
111
|
config,
|
|
111
112
|
isServer: false,
|
|
112
|
-
|
|
113
|
+
configureWebpackUtils,
|
|
113
114
|
});
|
|
114
115
|
return config;
|
|
115
116
|
}
|
|
116
117
|
async function createWebpackDevServer({ props, cliOptions, openUrlContext, }) {
|
|
118
|
+
const configureWebpackUtils = await (0, configure_1.createConfigureWebpackUtils)({
|
|
119
|
+
siteConfig: props.siteConfig,
|
|
120
|
+
});
|
|
117
121
|
const config = await getStartClientConfig({
|
|
118
122
|
props,
|
|
119
123
|
minify: cliOptions.minify ?? true,
|
|
120
124
|
poll: cliOptions.poll,
|
|
125
|
+
configureWebpackUtils,
|
|
121
126
|
});
|
|
122
127
|
const compiler = (0, webpack_1.default)(config);
|
|
123
128
|
registerWebpackE2ETestHook(compiler);
|
|
@@ -26,12 +26,14 @@ exports.DEFAULT_FASTER_CONFIG = {
|
|
|
26
26
|
swcJsLoader: false,
|
|
27
27
|
swcJsMinimizer: false,
|
|
28
28
|
mdxCrossCompilerCache: false,
|
|
29
|
+
rspackBundler: false,
|
|
29
30
|
};
|
|
30
31
|
// When using the "faster: true" shortcut
|
|
31
32
|
exports.DEFAULT_FASTER_CONFIG_TRUE = {
|
|
32
33
|
swcJsLoader: true,
|
|
33
34
|
swcJsMinimizer: true,
|
|
34
35
|
mdxCrossCompilerCache: true,
|
|
36
|
+
rspackBundler: true,
|
|
35
37
|
};
|
|
36
38
|
exports.DEFAULT_FUTURE_CONFIG = {
|
|
37
39
|
experimental_faster: exports.DEFAULT_FASTER_CONFIG,
|
|
@@ -147,6 +149,7 @@ const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
|
|
|
147
149
|
swcJsLoader: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsLoader),
|
|
148
150
|
swcJsMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsMinimizer),
|
|
149
151
|
mdxCrossCompilerCache: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache),
|
|
152
|
+
rspackBundler: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.rspackBundler),
|
|
150
153
|
}), utils_validation_1.Joi.boolean()
|
|
151
154
|
.required()
|
|
152
155
|
.custom((bool) => bool ? exports.DEFAULT_FASTER_CONFIG_TRUE : exports.DEFAULT_FASTER_CONFIG))
|
|
@@ -96,7 +96,7 @@ async function extractSourceCodeFileTranslations(sourceCodeFilePath, babelOption
|
|
|
96
96
|
ast: true,
|
|
97
97
|
// filename is important, because babel does not process the same files
|
|
98
98
|
// according to their js/ts extensions.
|
|
99
|
-
// See https://
|
|
99
|
+
// See https://x.com/NicoloRibaudo/status/1321130735605002243
|
|
100
100
|
filename: sourceCodeFilePath,
|
|
101
101
|
});
|
|
102
102
|
const translations = extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
|
package/lib/webpack/base.d.ts
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Configuration } from 'webpack';
|
|
8
|
-
import type { FasterConfig, Props } from '@docusaurus/types';
|
|
8
|
+
import type { ConfigureWebpackUtils, FasterConfig, Props } from '@docusaurus/types';
|
|
9
9
|
export declare const clientDir: string;
|
|
10
10
|
export declare function excludeJS(modulePath: string): boolean;
|
|
11
|
-
export declare function createBaseConfig({ props, isServer, minify, faster, }: {
|
|
11
|
+
export declare function createBaseConfig({ props, isServer, minify, faster, configureWebpackUtils, }: {
|
|
12
12
|
props: Props;
|
|
13
13
|
isServer: boolean;
|
|
14
14
|
minify: boolean;
|
|
15
15
|
faster: FasterConfig;
|
|
16
|
+
configureWebpackUtils: ConfigureWebpackUtils;
|
|
16
17
|
}): Promise<Configuration>;
|
package/lib/webpack/base.js
CHANGED
|
@@ -12,11 +12,11 @@ exports.createBaseConfig = createBaseConfig;
|
|
|
12
12
|
const tslib_1 = require("tslib");
|
|
13
13
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
14
14
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
|
-
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
16
15
|
const utils_1 = require("@docusaurus/utils");
|
|
17
16
|
const utils_2 = require("./utils");
|
|
18
17
|
const minification_1 = require("./minification");
|
|
19
18
|
const aliases_1 = require("./aliases");
|
|
19
|
+
const currentBundler_1 = require("./currentBundler");
|
|
20
20
|
const CSS_REGEX = /\.css$/i;
|
|
21
21
|
const CSS_MODULE_REGEX = /\.module\.css$/i;
|
|
22
22
|
exports.clientDir = path_1.default.join(__dirname, '..', 'client');
|
|
@@ -42,7 +42,7 @@ function excludeJS(modulePath) {
|
|
|
42
42
|
!/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
|
|
43
43
|
!LibrariesToTranspileRegex.test(modulePath));
|
|
44
44
|
}
|
|
45
|
-
async function createBaseConfig({ props, isServer, minify, faster, }) {
|
|
45
|
+
async function createBaseConfig({ props, isServer, minify, faster, configureWebpackUtils, }) {
|
|
46
46
|
const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
|
|
47
47
|
const totalPages = routesPaths.length;
|
|
48
48
|
const isProd = process.env.NODE_ENV === 'production';
|
|
@@ -52,6 +52,9 @@ async function createBaseConfig({ props, isServer, minify, faster, }) {
|
|
|
52
52
|
const mode = isProd ? 'production' : 'development';
|
|
53
53
|
const themeAliases = await (0, aliases_1.loadThemeAliases)({ siteDir, plugins });
|
|
54
54
|
const createJsLoader = await (0, utils_2.createJsLoaderFactory)({ siteConfig });
|
|
55
|
+
const CSSExtractPlugin = await (0, currentBundler_1.getCSSExtractPlugin)({
|
|
56
|
+
currentBundler: configureWebpackUtils.currentBundler,
|
|
57
|
+
});
|
|
55
58
|
return {
|
|
56
59
|
mode,
|
|
57
60
|
name,
|
|
@@ -185,7 +188,7 @@ async function createBaseConfig({ props, isServer, minify, faster, }) {
|
|
|
185
188
|
{
|
|
186
189
|
test: CSS_REGEX,
|
|
187
190
|
exclude: CSS_MODULE_REGEX,
|
|
188
|
-
use:
|
|
191
|
+
use: configureWebpackUtils.getStyleLoaders(isServer, {
|
|
189
192
|
importLoaders: 1,
|
|
190
193
|
sourceMap: !isProd,
|
|
191
194
|
}),
|
|
@@ -194,7 +197,7 @@ async function createBaseConfig({ props, isServer, minify, faster, }) {
|
|
|
194
197
|
// using the extension .module.css
|
|
195
198
|
{
|
|
196
199
|
test: CSS_MODULE_REGEX,
|
|
197
|
-
use:
|
|
200
|
+
use: configureWebpackUtils.getStyleLoaders(isServer, {
|
|
198
201
|
modules: {
|
|
199
202
|
// Using the same CSS Module class pattern in dev/prod on purpose
|
|
200
203
|
// See https://github.com/facebook/docusaurus/pull/10423
|
|
@@ -208,7 +211,7 @@ async function createBaseConfig({ props, isServer, minify, faster, }) {
|
|
|
208
211
|
],
|
|
209
212
|
},
|
|
210
213
|
plugins: [
|
|
211
|
-
new
|
|
214
|
+
new CSSExtractPlugin({
|
|
212
215
|
filename: isProd
|
|
213
216
|
? 'assets/css/[name].[contenthash:8].css'
|
|
214
217
|
: '[name].css',
|
package/lib/webpack/client.d.ts
CHANGED
|
@@ -4,20 +4,22 @@
|
|
|
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 { FasterConfig, Props } from '@docusaurus/types';
|
|
7
|
+
import type { ConfigureWebpackUtils, FasterConfig, Props } from '@docusaurus/types';
|
|
8
8
|
import type { Configuration } from 'webpack';
|
|
9
|
-
export declare function createStartClientConfig({ props, minify, poll, faster, }: {
|
|
9
|
+
export declare function createStartClientConfig({ props, minify, poll, faster, configureWebpackUtils, }: {
|
|
10
10
|
props: Props;
|
|
11
11
|
minify: boolean;
|
|
12
12
|
poll: number | boolean | undefined;
|
|
13
13
|
faster: FasterConfig;
|
|
14
|
+
configureWebpackUtils: ConfigureWebpackUtils;
|
|
14
15
|
}): Promise<{
|
|
15
16
|
clientConfig: Configuration;
|
|
16
17
|
}>;
|
|
17
|
-
export declare function createBuildClientConfig({ props, minify, faster, bundleAnalyzer, }: {
|
|
18
|
+
export declare function createBuildClientConfig({ props, minify, faster, configureWebpackUtils, bundleAnalyzer, }: {
|
|
18
19
|
props: Props;
|
|
19
20
|
minify: boolean;
|
|
20
21
|
faster: FasterConfig;
|
|
22
|
+
configureWebpackUtils: ConfigureWebpackUtils;
|
|
21
23
|
bundleAnalyzer: boolean;
|
|
22
24
|
}): Promise<{
|
|
23
25
|
config: Configuration;
|
package/lib/webpack/client.js
CHANGED
|
@@ -21,12 +21,13 @@ const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAsset
|
|
|
21
21
|
const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("./plugins/CleanWebpackPlugin"));
|
|
22
22
|
const ForceTerminatePlugin_1 = tslib_1.__importDefault(require("./plugins/ForceTerminatePlugin"));
|
|
23
23
|
const StaticDirectoriesCopyPlugin_1 = require("./plugins/StaticDirectoriesCopyPlugin");
|
|
24
|
-
async function createBaseClientConfig({ props, hydrate, minify, faster, }) {
|
|
24
|
+
async function createBaseClientConfig({ props, hydrate, minify, faster, configureWebpackUtils, }) {
|
|
25
25
|
const baseConfig = await (0, base_1.createBaseConfig)({
|
|
26
26
|
props,
|
|
27
27
|
isServer: false,
|
|
28
28
|
minify,
|
|
29
29
|
faster,
|
|
30
|
+
configureWebpackUtils,
|
|
30
31
|
});
|
|
31
32
|
return (0, webpack_merge_1.default)(baseConfig, {
|
|
32
33
|
// Useless, disabled on purpose (errors on existing sites with no
|
|
@@ -35,7 +36,7 @@ async function createBaseClientConfig({ props, hydrate, minify, faster, }) {
|
|
|
35
36
|
entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
|
|
36
37
|
optimization: {
|
|
37
38
|
// Keep the runtime chunk separated to enable long term caching
|
|
38
|
-
// https://
|
|
39
|
+
// https://x.com/wSokra/status/969679223278505985
|
|
39
40
|
runtimeChunk: true,
|
|
40
41
|
},
|
|
41
42
|
plugins: [
|
|
@@ -47,18 +48,22 @@ async function createBaseClientConfig({ props, hydrate, minify, faster, }) {
|
|
|
47
48
|
new webpackbar_1.default({
|
|
48
49
|
name: 'Client',
|
|
49
50
|
}),
|
|
50
|
-
await (0, StaticDirectoriesCopyPlugin_1.createStaticDirectoriesCopyPlugin)({
|
|
51
|
+
await (0, StaticDirectoriesCopyPlugin_1.createStaticDirectoriesCopyPlugin)({
|
|
52
|
+
props,
|
|
53
|
+
currentBundler: configureWebpackUtils.currentBundler,
|
|
54
|
+
}),
|
|
51
55
|
].filter(Boolean),
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
// client config when running "docusaurus start"
|
|
55
|
-
async function createStartClientConfig({ props, minify, poll, faster, }) {
|
|
59
|
+
async function createStartClientConfig({ props, minify, poll, faster, configureWebpackUtils, }) {
|
|
56
60
|
const { siteConfig, headTags, preBodyTags, postBodyTags } = props;
|
|
57
61
|
const clientConfig = (0, webpack_merge_1.default)(await createBaseClientConfig({
|
|
58
62
|
props,
|
|
59
63
|
minify,
|
|
60
64
|
hydrate: false,
|
|
61
65
|
faster,
|
|
66
|
+
configureWebpackUtils,
|
|
62
67
|
}), {
|
|
63
68
|
watchOptions: {
|
|
64
69
|
ignored: /node_modules\/(?!@docusaurus)/,
|
|
@@ -85,7 +90,7 @@ async function createStartClientConfig({ props, minify, poll, faster, }) {
|
|
|
85
90
|
return { clientConfig };
|
|
86
91
|
}
|
|
87
92
|
// client config when running "docusaurus build"
|
|
88
|
-
async function createBuildClientConfig({ props, minify, faster, bundleAnalyzer, }) {
|
|
93
|
+
async function createBuildClientConfig({ props, minify, faster, configureWebpackUtils, bundleAnalyzer, }) {
|
|
89
94
|
// Apply user webpack config.
|
|
90
95
|
const { generatedFilesDir, siteConfig } = props;
|
|
91
96
|
const router = siteConfig.future.experimental_router;
|
|
@@ -93,7 +98,13 @@ async function createBuildClientConfig({ props, minify, faster, bundleAnalyzer,
|
|
|
93
98
|
// This is because it will always be a client-rendered React app
|
|
94
99
|
const hydrate = router !== 'hash';
|
|
95
100
|
const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
|
|
96
|
-
const config = (0, webpack_merge_1.default)(await createBaseClientConfig({
|
|
101
|
+
const config = (0, webpack_merge_1.default)(await createBaseClientConfig({
|
|
102
|
+
props,
|
|
103
|
+
minify,
|
|
104
|
+
faster,
|
|
105
|
+
configureWebpackUtils,
|
|
106
|
+
hydrate,
|
|
107
|
+
}), {
|
|
97
108
|
plugins: [
|
|
98
109
|
new ForceTerminatePlugin_1.default(),
|
|
99
110
|
// Remove/clean build folders before building bundles.
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { createJsLoaderFactory } from './utils';
|
|
8
|
+
import { getCurrentBundler } from './currentBundler';
|
|
8
9
|
import type { Configuration } from 'webpack';
|
|
9
10
|
import type { Plugin, ConfigureWebpackUtils, LoadedPlugin } from '@docusaurus/types';
|
|
10
11
|
/**
|
|
@@ -12,7 +13,7 @@ import type { Plugin, ConfigureWebpackUtils, LoadedPlugin } from '@docusaurus/ty
|
|
|
12
13
|
* @param config the Docusaurus config
|
|
13
14
|
*/
|
|
14
15
|
export declare function createConfigureWebpackUtils({ siteConfig, }: {
|
|
15
|
-
siteConfig: Parameters<typeof createJsLoaderFactory>[0]['siteConfig'];
|
|
16
|
+
siteConfig: Parameters<typeof createJsLoaderFactory>[0]['siteConfig'] & Parameters<typeof getCurrentBundler>[0]['siteConfig'];
|
|
16
17
|
}): Promise<ConfigureWebpackUtils>;
|
|
17
18
|
/**
|
|
18
19
|
* Helper function to modify webpack config
|
|
@@ -23,17 +24,17 @@ export declare function createConfigureWebpackUtils({ siteConfig, }: {
|
|
|
23
24
|
* @param content content loaded by the plugin
|
|
24
25
|
* @returns final/ modified webpack config
|
|
25
26
|
*/
|
|
26
|
-
export declare function applyConfigureWebpack({ configureWebpack, config, isServer,
|
|
27
|
+
export declare function applyConfigureWebpack({ configureWebpack, config, isServer, configureWebpackUtils, content, }: {
|
|
27
28
|
configureWebpack: NonNullable<Plugin['configureWebpack']>;
|
|
28
29
|
config: Configuration;
|
|
29
30
|
isServer: boolean;
|
|
30
|
-
|
|
31
|
+
configureWebpackUtils: ConfigureWebpackUtils;
|
|
31
32
|
content: unknown;
|
|
32
33
|
}): Configuration;
|
|
33
34
|
export declare function applyConfigurePostCss(configurePostCss: NonNullable<Plugin['configurePostCss']>, config: Configuration): Configuration;
|
|
34
|
-
export declare function executePluginsConfigureWebpack({ plugins, config: configInput, isServer,
|
|
35
|
+
export declare function executePluginsConfigureWebpack({ plugins, config: configInput, isServer, configureWebpackUtils, }: {
|
|
35
36
|
plugins: LoadedPlugin[];
|
|
36
37
|
config: Configuration;
|
|
37
38
|
isServer: boolean;
|
|
38
|
-
|
|
39
|
+
configureWebpackUtils: ConfigureWebpackUtils;
|
|
39
40
|
}): Configuration;
|
package/lib/webpack/configure.js
CHANGED
|
@@ -12,14 +12,19 @@ exports.applyConfigurePostCss = applyConfigurePostCss;
|
|
|
12
12
|
exports.executePluginsConfigureWebpack = executePluginsConfigureWebpack;
|
|
13
13
|
const webpack_merge_1 = require("webpack-merge");
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
|
+
const currentBundler_1 = require("./currentBundler");
|
|
15
16
|
/**
|
|
16
17
|
* Creates convenient utils to inject into the configureWebpack() lifecycle
|
|
17
18
|
* @param config the Docusaurus config
|
|
18
19
|
*/
|
|
19
20
|
async function createConfigureWebpackUtils({ siteConfig, }) {
|
|
21
|
+
const currentBundler = await (0, currentBundler_1.getCurrentBundler)({ siteConfig });
|
|
22
|
+
const getStyleLoaders = await (0, utils_1.createStyleLoadersFactory)({ currentBundler });
|
|
23
|
+
const getJSLoader = await (0, utils_1.createJsLoaderFactory)({ siteConfig });
|
|
20
24
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
currentBundler,
|
|
26
|
+
getStyleLoaders,
|
|
27
|
+
getJSLoader,
|
|
23
28
|
};
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
@@ -31,9 +36,9 @@ async function createConfigureWebpackUtils({ siteConfig, }) {
|
|
|
31
36
|
* @param content content loaded by the plugin
|
|
32
37
|
* @returns final/ modified webpack config
|
|
33
38
|
*/
|
|
34
|
-
function applyConfigureWebpack({ configureWebpack, config, isServer,
|
|
39
|
+
function applyConfigureWebpack({ configureWebpack, config, isServer, configureWebpackUtils, content, }) {
|
|
35
40
|
if (typeof configureWebpack === 'function') {
|
|
36
|
-
const { mergeStrategy, ...res } = configureWebpack(config, isServer,
|
|
41
|
+
const { mergeStrategy, ...res } = configureWebpack(config, isServer, configureWebpackUtils, content) ?? {};
|
|
37
42
|
const customizeRules = mergeStrategy ?? {};
|
|
38
43
|
return (0, webpack_merge_1.mergeWithCustomize)({
|
|
39
44
|
customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
|
|
@@ -80,7 +85,7 @@ function executePluginsConfigurePostCss({ plugins, config, }) {
|
|
|
80
85
|
return resultConfig;
|
|
81
86
|
}
|
|
82
87
|
// Plugin Lifecycle - configureWebpack()
|
|
83
|
-
function executePluginsConfigureWebpack({ plugins, config: configInput, isServer,
|
|
88
|
+
function executePluginsConfigureWebpack({ plugins, config: configInput, isServer, configureWebpackUtils, }) {
|
|
84
89
|
let config = configInput;
|
|
85
90
|
// Step1 - Configure Webpack
|
|
86
91
|
plugins.forEach((plugin) => {
|
|
@@ -90,7 +95,7 @@ function executePluginsConfigureWebpack({ plugins, config: configInput, isServer
|
|
|
90
95
|
configureWebpack: configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
91
96
|
config,
|
|
92
97
|
isServer,
|
|
93
|
-
|
|
98
|
+
configureWebpackUtils,
|
|
94
99
|
content: plugin.content,
|
|
95
100
|
});
|
|
96
101
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -4,8 +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
|
|
8
|
-
import type {
|
|
9
|
-
export declare function createStaticDirectoriesCopyPlugin({ props, }: {
|
|
7
|
+
import type { CurrentBundler, Props } from '@docusaurus/types';
|
|
8
|
+
import type { WebpackPluginInstance } from 'webpack';
|
|
9
|
+
export declare function createStaticDirectoriesCopyPlugin({ props, currentBundler, }: {
|
|
10
10
|
props: Props;
|
|
11
|
-
|
|
11
|
+
currentBundler: CurrentBundler;
|
|
12
|
+
}): Promise<WebpackPluginInstance | undefined>;
|
|
@@ -10,8 +10,11 @@ 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, }) {
|
|
13
|
+
const currentBundler_1 = require("../currentBundler");
|
|
14
|
+
async function createStaticDirectoriesCopyPlugin({ props, currentBundler, }) {
|
|
15
|
+
const CopyPlugin = await (0, currentBundler_1.getCopyPlugin)({
|
|
16
|
+
currentBundler,
|
|
17
|
+
});
|
|
15
18
|
const { outDir, siteDir, siteConfig: { staticDirectories: staticDirectoriesOption }, } = props;
|
|
16
19
|
// The staticDirectories option can contain empty directories, or non-existent
|
|
17
20
|
// directories (e.g. user deleted `static`). Instead of issuing an error, we
|
|
@@ -28,7 +31,7 @@ async function createStaticDirectoriesCopyPlugin({ props, }) {
|
|
|
28
31
|
if (staticDirectories.length === 0) {
|
|
29
32
|
return undefined;
|
|
30
33
|
}
|
|
31
|
-
return new
|
|
34
|
+
return new CopyPlugin({
|
|
32
35
|
patterns: staticDirectories.map((dir) => ({
|
|
33
36
|
from: dir,
|
|
34
37
|
to: outDir,
|
package/lib/webpack/server.d.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
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 { Props } from '@docusaurus/types';
|
|
7
|
+
import type { ConfigureWebpackUtils, Props } from '@docusaurus/types';
|
|
8
8
|
import type { Configuration } from 'webpack';
|
|
9
|
-
export default function createServerConfig(
|
|
9
|
+
export default function createServerConfig({ props, configureWebpackUtils, }: {
|
|
10
10
|
props: Props;
|
|
11
|
+
configureWebpackUtils: ConfigureWebpackUtils;
|
|
11
12
|
}): Promise<{
|
|
12
13
|
config: Configuration;
|
|
13
14
|
serverBundlePath: string;
|
package/lib/webpack/server.js
CHANGED
|
@@ -13,13 +13,13 @@ const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
14
|
const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
|
|
15
15
|
const base_1 = require("./base");
|
|
16
|
-
async function createServerConfig(
|
|
17
|
-
const { props } = params;
|
|
16
|
+
async function createServerConfig({ props, configureWebpackUtils, }) {
|
|
18
17
|
const baseConfig = await (0, base_1.createBaseConfig)({
|
|
19
18
|
props,
|
|
20
19
|
isServer: true,
|
|
21
20
|
minify: false,
|
|
22
21
|
faster: props.siteConfig.future.experimental_faster,
|
|
22
|
+
configureWebpackUtils,
|
|
23
23
|
});
|
|
24
24
|
const outputFilename = 'server.bundle.js';
|
|
25
25
|
const outputDir = path_1.default.join(props.outDir, '__server');
|
package/lib/webpack/utils.d.ts
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
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 webpack, { type Configuration
|
|
8
|
-
import type { ConfigureWebpackUtils, DocusaurusConfig } from '@docusaurus/types';
|
|
7
|
+
import webpack, { type Configuration } from 'webpack';
|
|
8
|
+
import type { ConfigureWebpackUtils, CurrentBundler, DocusaurusConfig } from '@docusaurus/types';
|
|
9
9
|
import type { TransformOptions } from '@babel/core';
|
|
10
10
|
export declare function formatStatsErrorMessage(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): string | undefined;
|
|
11
11
|
export declare function printStatsWarnings(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): void;
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
}):
|
|
12
|
+
export declare function createStyleLoadersFactory({ currentBundler, }: {
|
|
13
|
+
currentBundler: CurrentBundler;
|
|
14
|
+
}): Promise<ConfigureWebpackUtils['getStyleLoaders']>;
|
|
15
15
|
export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
|
|
16
16
|
export declare function getBabelOptions({ isServer, babelOptions, }?: {
|
|
17
17
|
isServer?: boolean;
|
package/lib/webpack/utils.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.formatStatsErrorMessage = formatStatsErrorMessage;
|
|
10
10
|
exports.printStatsWarnings = printStatsWarnings;
|
|
11
|
-
exports.
|
|
11
|
+
exports.createStyleLoadersFactory = createStyleLoadersFactory;
|
|
12
12
|
exports.getCustomBabelConfigFilePath = getCustomBabelConfigFilePath;
|
|
13
13
|
exports.getBabelOptions = getBabelOptions;
|
|
14
14
|
exports.createJsLoaderFactory = createJsLoaderFactory;
|
|
@@ -20,10 +20,10 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
20
20
|
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
21
21
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
22
22
|
const utils_1 = require("@docusaurus/utils");
|
|
23
|
-
const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
|
|
24
23
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
25
24
|
const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
|
|
26
25
|
const faster_1 = require("../faster");
|
|
26
|
+
const currentBundler_1 = require("./currentBundler");
|
|
27
27
|
function formatStatsErrorMessage(statsJson) {
|
|
28
28
|
if (statsJson?.errors?.length) {
|
|
29
29
|
// TODO formatWebpackMessages does not print stack-traces
|
|
@@ -43,60 +43,62 @@ function printStatsWarnings(statsJson) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
async function createStyleLoadersFactory({ currentBundler, }) {
|
|
47
|
+
const CssExtractPlugin = await (0, currentBundler_1.getCSSExtractPlugin)({ currentBundler });
|
|
48
|
+
return function getStyleLoaders(isServer, cssOptionsArg = {}) {
|
|
49
|
+
const cssOptions = {
|
|
50
|
+
// TODO turn esModule on later, see https://github.com/facebook/docusaurus/pull/6424
|
|
51
|
+
esModule: false,
|
|
52
|
+
...cssOptionsArg,
|
|
53
|
+
};
|
|
54
|
+
// On the server we don't really need to extract/emit CSS
|
|
55
|
+
// We only need to transform CSS module imports to a styles object
|
|
56
|
+
if (isServer) {
|
|
57
|
+
return cssOptions.modules
|
|
58
|
+
? [
|
|
59
|
+
{
|
|
60
|
+
loader: require.resolve('css-loader'),
|
|
61
|
+
options: cssOptions,
|
|
62
|
+
},
|
|
63
|
+
]
|
|
64
|
+
: // Ignore regular CSS files
|
|
65
|
+
[{ loader: require.resolve('null-loader') }];
|
|
66
|
+
}
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
loader: CssExtractPlugin.loader,
|
|
70
|
+
options: {
|
|
71
|
+
esModule: true,
|
|
61
72
|
},
|
|
62
|
-
]
|
|
63
|
-
: // Ignore regular CSS files
|
|
64
|
-
[{ loader: require.resolve('null-loader') }];
|
|
65
|
-
}
|
|
66
|
-
return [
|
|
67
|
-
{
|
|
68
|
-
loader: mini_css_extract_plugin_1.default.loader,
|
|
69
|
-
options: {
|
|
70
|
-
esModule: true,
|
|
71
73
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
{
|
|
75
|
+
loader: require.resolve('css-loader'),
|
|
76
|
+
options: cssOptions,
|
|
77
|
+
},
|
|
78
|
+
// TODO apart for configurePostCss(), do we really need this loader?
|
|
79
|
+
// Note: using postcss here looks inefficient/duplicate
|
|
80
|
+
// But in practice, it's not a big deal because css-loader also uses postcss
|
|
81
|
+
// and is able to reuse the parsed AST from postcss-loader
|
|
82
|
+
// See https://github.com/webpack-contrib/css-loader/blob/master/src/index.js#L159
|
|
83
|
+
{
|
|
84
|
+
// Options for PostCSS as we reference these options twice
|
|
85
|
+
// Adds vendor prefixing based on your specified browser support in
|
|
86
|
+
// package.json
|
|
87
|
+
loader: require.resolve('postcss-loader'),
|
|
88
|
+
options: {
|
|
89
|
+
postcssOptions: {
|
|
90
|
+
// Necessary for external CSS imports to work
|
|
91
|
+
// https://github.com/facebook/create-react-app/issues/2677
|
|
92
|
+
ident: 'postcss',
|
|
93
|
+
plugins: [
|
|
94
|
+
// eslint-disable-next-line global-require
|
|
95
|
+
require('autoprefixer'),
|
|
96
|
+
],
|
|
97
|
+
},
|
|
96
98
|
},
|
|
97
99
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
];
|
|
101
|
+
};
|
|
100
102
|
}
|
|
101
103
|
async function getCustomBabelConfigFilePath(siteDir) {
|
|
102
104
|
const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
|
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-6079",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"@babel/runtime": "^7.22.6",
|
|
44
44
|
"@babel/runtime-corejs3": "^7.22.6",
|
|
45
45
|
"@babel/traverse": "^7.22.8",
|
|
46
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
47
|
-
"@docusaurus/logger": "0.0.0-
|
|
48
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
49
|
-
"@docusaurus/utils": "0.0.0-
|
|
50
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
51
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
46
|
+
"@docusaurus/cssnano-preset": "0.0.0-6079",
|
|
47
|
+
"@docusaurus/logger": "0.0.0-6079",
|
|
48
|
+
"@docusaurus/mdx-loader": "0.0.0-6079",
|
|
49
|
+
"@docusaurus/utils": "0.0.0-6079",
|
|
50
|
+
"@docusaurus/utils-common": "0.0.0-6079",
|
|
51
|
+
"@docusaurus/utils-validation": "0.0.0-6079",
|
|
52
52
|
"autoprefixer": "^10.4.14",
|
|
53
53
|
"babel-loader": "^9.1.3",
|
|
54
54
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"webpackbar": "^5.0.2"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
108
|
-
"@docusaurus/types": "0.0.0-
|
|
107
|
+
"@docusaurus/module-type-aliases": "0.0.0-6079",
|
|
108
|
+
"@docusaurus/types": "0.0.0-6079",
|
|
109
109
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
110
110
|
"@types/detect-port": "^1.3.3",
|
|
111
111
|
"@types/react-dom": "^18.2.7",
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
"engines": {
|
|
133
133
|
"node": ">=18.0"
|
|
134
134
|
},
|
|
135
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "88a9e6f7cb97ad1b99679b12437bcb40eecb3fa0"
|
|
136
136
|
}
|