@docusaurus/core 4.0.0-canary-6912 → 4.0.0-canary-6917

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.
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { RspackDevServer } from '@docusaurus/bundler';
8
- import WebpackDevServer from 'webpack-dev-server';
9
8
  import type { StartCLIOptions } from './start';
10
9
  import type { Props } from '@docusaurus/types';
10
+ import type WebpackDevServer from 'webpack-dev-server';
11
11
  import type { OpenUrlContext } from './utils';
12
12
  export declare function createWebpackDevServer({ props, cliOptions, openUrlContext, }: {
13
13
  props: Props;
@@ -12,7 +12,6 @@ const node_path_1 = tslib_1.__importDefault(require("node:path"));
12
12
  const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
13
13
  const bundler_1 = require("@docusaurus/bundler");
14
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
- const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
16
15
  const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("../utils/legacy/evalSourceMapMiddleware"));
17
16
  const watcher_1 = require("./watcher");
18
17
  const getHttpsConfig_1 = tslib_1.__importDefault(require("../../webpack/utils/getHttpsConfig"));
@@ -145,7 +144,9 @@ async function createWebpackDevServer({ props, cliOptions, openUrlContext, }) {
145
144
  }
146
145
  async function createDevServer({ devServerConfig, compiler, currentBundler, }) {
147
146
  if (currentBundler.name === 'webpack') {
148
- return new webpack_dev_server_1.default(devServerConfig, compiler);
147
+ // Imported lazily, only when Webpack is used
148
+ const { default: WebpackDevServer } = await import('webpack-dev-server');
149
+ return new WebpackDevServer(devServerConfig, compiler);
149
150
  }
150
151
  // Docusaurus bundler configs are typed with Webpack types
151
152
  return new bundler_1.RspackDevServer(devServerConfig, compiler);
@@ -20,6 +20,13 @@ const BundlerCPUProfilerPlugin_1 = require("./plugins/BundlerCPUProfilerPlugin")
20
20
  const CSS_REGEX = /\.css$/i;
21
21
  const CSS_MODULE_REGEX = /\.module\.css$/i;
22
22
  exports.clientDir = node_path_1.default.join(__dirname, '..', 'client');
23
+ // The RealContentHashPlugin replaces every occurrence of a provisional chunk
24
+ // hash in all assets, even inside unrelated hex strings (file-loader asset
25
+ // names, colors, numbers...). The client and server compilations do it
26
+ // independently, so a false positive can make the SSG HTML reference a missing
27
+ // file. 10 chars instead of 8 makes it ~256x less likely.
28
+ // See https://github.com/web-infra-dev/rspack/issues/8474
29
+ const contentHash = '[contenthash:10]';
23
30
  function getReactAliases(siteDir) {
24
31
  // Escape hatch
25
32
  if (process.env.DOCUSAURUS_NO_REACT_ALIASES) {
@@ -114,9 +121,9 @@ async function createBaseConfig({ props, isServer, minify, configureWebpackUtils
114
121
  output: {
115
122
  pathinfo: false,
116
123
  path: outDir,
117
- filename: isProd ? 'assets/js/[name].[contenthash:8].js' : '[name].js',
124
+ filename: isProd ? `assets/js/[name].${contentHash}.js` : '[name].js',
118
125
  chunkFilename: isProd
119
- ? 'assets/js/[name].[contenthash:8].js'
126
+ ? `assets/js/[name].${contentHash}.js`
120
127
  : '[name].js',
121
128
  publicPath: siteConfig.future.experimental_router === 'hash' ? 'auto' : baseUrl,
122
129
  hashFunction: 'xxhash64',
@@ -252,10 +259,10 @@ async function createBaseConfig({ props, isServer, minify, configureWebpackUtils
252
259
  plugins: [
253
260
  new CSSExtractPlugin({
254
261
  filename: isProd
255
- ? 'assets/css/[name].[contenthash:8].css'
262
+ ? `assets/css/[name].${contentHash}.css`
256
263
  : '[name].css',
257
264
  chunkFilename: isProd
258
- ? 'assets/css/[name].[contenthash:8].css'
265
+ ? `assets/css/[name].${contentHash}.css`
259
266
  : '[name].css',
260
267
  // Remove css order warnings if css imports are not sorted
261
268
  // alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
@@ -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 { type Compiler } from 'webpack';
7
+ import type { Compiler } from 'webpack';
8
8
  export default class ChunkAssetPlugin {
9
9
  apply(compiler: Compiler): void;
10
10
  }
@@ -6,8 +6,6 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- const tslib_1 = require("tslib");
10
- const webpack_1 = tslib_1.__importDefault(require("webpack"));
11
9
  // Adds a custom Docusaurus Webpack runtime function `__webpack_require__.gca`
12
10
  // gca = Get Chunk Asset, it converts a chunkName to a JS asset URL
13
11
  // It is called in Core client/docusaurus.ts for chunk preloading/prefetching
@@ -16,7 +14,7 @@ const webpack_1 = tslib_1.__importDefault(require("webpack"));
16
14
  // The name of the custom Docusaurus Webpack runtime function
17
15
  const DocusaurusGetChunkAssetFn = '__webpack_require__.gca';
18
16
  const PluginName = 'Docusaurus-ChunkAssetPlugin';
19
- function generateGetChunkAssetRuntimeCode(chunk) {
17
+ function generateGetChunkAssetRuntimeCode({ chunk, bundler, }) {
20
18
  const chunkIdToName = chunk.getChunkMaps(false).name;
21
19
  const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
22
20
  chunkName,
@@ -30,10 +28,10 @@ function generateGetChunkAssetRuntimeCode(chunk) {
30
28
  // getChunkScriptFilename = __webpack_require__.u
31
29
  // Example: getChunkScriptFilename("814f3328") = "814f3328.03fcc178.js"
32
30
  // https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/GetChunkFilenameRuntimeModule.js
33
- getChunkScriptFilename, } = webpack_1.default.RuntimeGlobals;
31
+ getChunkScriptFilename, } = bundler.RuntimeGlobals;
34
32
  const code = `// Docusaurus function to get chunk asset
35
33
  ${DocusaurusGetChunkAssetFn} = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return ${publicPath} + ${getChunkScriptFilename}(chunkId); };`;
36
- return webpack_1.default.Template.asString(code);
34
+ return bundler.Template.asString(code);
37
35
  }
38
36
  /*
39
37
  Note: we previously used `MainTemplate.hooks.requireExtensions.tap()`
@@ -44,6 +42,9 @@ ${DocusaurusGetChunkAssetFn} = function(chunkId) { chunkId = ${JSON.stringify(ch
44
42
  */
45
43
  class ChunkAssetPlugin {
46
44
  apply(compiler) {
45
+ // Use the compiler's bundler instance (Webpack or Rspack)
46
+ // This avoids loading Webpack when using Rspack
47
+ const ChunkAssetRuntimeModule = createChunkAssetRuntimeModuleClass(compiler.webpack);
47
48
  compiler.hooks.thisCompilation.tap(PluginName, (compilation) => {
48
49
  compilation.hooks.additionalTreeRuntimeRequirements.tap(PluginName, (chunk) => {
49
50
  compilation.addRuntimeModule(chunk, new ChunkAssetRuntimeModule());
@@ -55,12 +56,14 @@ exports.default = ChunkAssetPlugin;
55
56
  // Inspired by https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/CompatRuntimeModule.js
56
57
  // See also https://rspack.dev/api/javascript-api/compilation#addruntimemodule
57
58
  // See also https://rspack.dev/api/plugin-api/compilation-hooks#additionaltreeruntimerequirements
58
- class ChunkAssetRuntimeModule extends webpack_1.default.RuntimeModule {
59
- constructor() {
60
- super('ChunkAssetRuntimeModule', webpack_1.default.RuntimeModule.STAGE_ATTACH);
61
- this.fullHash = true;
62
- }
63
- generate() {
64
- return generateGetChunkAssetRuntimeCode(this.chunk);
65
- }
59
+ function createChunkAssetRuntimeModuleClass(bundler) {
60
+ return class ChunkAssetRuntimeModule extends bundler.RuntimeModule {
61
+ constructor() {
62
+ super('ChunkAssetRuntimeModule', bundler.RuntimeModule.STAGE_ATTACH);
63
+ this.fullHash = true;
64
+ }
65
+ generate() {
66
+ return generateGetChunkAssetRuntimeCode({ chunk: this.chunk, bundler });
67
+ }
68
+ };
66
69
  }
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": "4.0.0-canary-6912",
4
+ "version": "4.0.0-canary-6917",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -33,15 +33,15 @@
33
33
  "url": "https://github.com/facebook/docusaurus/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@docusaurus/babel": "4.0.0-canary-6912",
37
- "@docusaurus/bundler": "4.0.0-canary-6912",
38
- "@docusaurus/fs": "4.0.0-canary-6912",
39
- "@docusaurus/glob": "4.0.0-canary-6912",
40
- "@docusaurus/logger": "4.0.0-canary-6912",
41
- "@docusaurus/mdx-loader": "4.0.0-canary-6912",
42
- "@docusaurus/utils": "4.0.0-canary-6912",
43
- "@docusaurus/utils-common": "4.0.0-canary-6912",
44
- "@docusaurus/utils-validation": "4.0.0-canary-6912",
36
+ "@docusaurus/babel": "4.0.0-canary-6917",
37
+ "@docusaurus/bundler": "4.0.0-canary-6917",
38
+ "@docusaurus/fs": "4.0.0-canary-6917",
39
+ "@docusaurus/glob": "4.0.0-canary-6917",
40
+ "@docusaurus/logger": "4.0.0-canary-6917",
41
+ "@docusaurus/mdx-loader": "4.0.0-canary-6917",
42
+ "@docusaurus/utils": "4.0.0-canary-6917",
43
+ "@docusaurus/utils-common": "4.0.0-canary-6917",
44
+ "@docusaurus/utils-validation": "4.0.0-canary-6917",
45
45
  "@rspack/core": "^2.2.3",
46
46
  "@rspack/dev-server": "^2.2.1",
47
47
  "boxen": "^9.0.0",
@@ -74,8 +74,8 @@
74
74
  "webpack-merge": "^6.0.1"
75
75
  },
76
76
  "devDependencies": {
77
- "@docusaurus/module-type-aliases": "4.0.0-canary-6912",
78
- "@docusaurus/types": "4.0.0-canary-6912",
77
+ "@docusaurus/module-type-aliases": "4.0.0-canary-6917",
78
+ "@docusaurus/types": "4.0.0-canary-6917",
79
79
  "@total-typescript/shoehorn": "^0.1.2",
80
80
  "@types/escape-html": "^1.0.4",
81
81
  "@types/history": "^4.7.11",
@@ -96,5 +96,5 @@
96
96
  "engines": {
97
97
  "node": ">=24.21"
98
98
  },
99
- "gitHead": "0678e3df2754a88376515d4fc9cc9b03819d424d"
99
+ "gitHead": "ee71afc5cacf13c6198155e64c4c7ab89c0d7eef"
100
100
  }