@docusaurus/core 0.0.0-6068 → 0.0.0-6072

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.
@@ -25,11 +25,13 @@ exports.DEFAULT_STORAGE_CONFIG = {
25
25
  exports.DEFAULT_FASTER_CONFIG = {
26
26
  swcJsLoader: false,
27
27
  swcJsMinimizer: false,
28
+ mdxCrossCompilerCache: false,
28
29
  };
29
30
  // When using the "faster: true" shortcut
30
31
  exports.DEFAULT_FASTER_CONFIG_TRUE = {
31
32
  swcJsLoader: true,
32
33
  swcJsMinimizer: true,
34
+ mdxCrossCompilerCache: true,
33
35
  };
34
36
  exports.DEFAULT_FUTURE_CONFIG = {
35
37
  experimental_faster: exports.DEFAULT_FASTER_CONFIG,
@@ -144,6 +146,7 @@ const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
144
146
  .try(utils_validation_1.Joi.object({
145
147
  swcJsLoader: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsLoader),
146
148
  swcJsMinimizer: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsMinimizer),
149
+ mdxCrossCompilerCache: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache),
147
150
  }), utils_validation_1.Joi.boolean()
148
151
  .required()
149
152
  .custom((bool) => bool ? exports.DEFAULT_FASTER_CONFIG_TRUE : exports.DEFAULT_FASTER_CONFIG))
@@ -60,6 +60,7 @@ function createBootstrapPlugin({ siteDir, siteConfig, }) {
60
60
  */
61
61
  async function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
62
62
  const mdxLoaderItem = await (0, mdx_loader_1.createMDXLoaderItem)({
63
+ useCrossCompilerCache: siteConfig.future.experimental_faster.mdxCrossCompilerCache,
63
64
  admonitions: true,
64
65
  staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
65
66
  siteDir,
@@ -5,17 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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
8
  export default class ChunkAssetPlugin {
20
9
  apply(compiler: Compiler): void;
21
10
  }
@@ -8,44 +8,57 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
11
- const pluginName = 'chunk-asset-plugin';
12
- /**
13
- * We modify webpack runtime to add an extra function called
14
- * "__webpack_require__.gca" that will allow us to get the corresponding chunk
15
- * asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
16
- * For example: if you have a chunk named "my-chunk-name" that will map to
17
- * "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
18
- * __webpack_require__.gca("my-chunk-name") will return
19
- * "/publicPath/0a84b5e7.c8e35c7a.js"
20
- *
21
- * "gca" stands for "get chunk asset"
11
+ // Adds a custom Docusaurus Webpack runtime function `__webpack_require__.gca`
12
+ // gca = Get Chunk Asset, it converts a chunkName to a JS asset URL
13
+ // It is called in Core client/docusaurus.ts for chunk preloading/prefetching
14
+ // Example: gca("814f3328") = "/baseUrl/assets/js/814f3328.03fcc178.js"
15
+ // See also: https://github.com/facebook/docusaurus/pull/10485
16
+ // The name of the custom Docusaurus Webpack runtime function
17
+ const DocusaurusGetChunkAssetFn = '__webpack_require__.gca';
18
+ const PluginName = 'Docusaurus-ChunkAssetPlugin';
19
+ function generateGetChunkAssetRuntimeCode(chunk) {
20
+ const chunkIdToName = chunk.getChunkMaps(false).name;
21
+ const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
22
+ chunkName,
23
+ chunkId,
24
+ ]));
25
+ const {
26
+ // publicPath = __webpack_require__.p
27
+ // Example: "/" or "/baseUrl/"
28
+ // https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/PublicPathRuntimeModule.js
29
+ publicPath,
30
+ // getChunkScriptFilename = __webpack_require__.u
31
+ // Example: getChunkScriptFilename("814f3328") = "814f3328.03fcc178.js"
32
+ // https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/GetChunkFilenameRuntimeModule.js
33
+ getChunkScriptFilename, } = webpack_1.default.RuntimeGlobals;
34
+ const code = `// Docusaurus function to get chunk asset
35
+ ${DocusaurusGetChunkAssetFn} = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return ${publicPath} + ${getChunkScriptFilename}(chunkId); };`;
36
+ return webpack_1.default.Template.asString(code);
37
+ }
38
+ /*
39
+ Note: we previously used `MainTemplate.hooks.requireExtensions.tap()`
40
+ But it will be removed in Webpack 6 and is not supported by Rspack
41
+ So instead we use equivalent code inspired by:
42
+ - https://github.com/webpack/webpack/blob/v5.94.0/lib/RuntimePlugin.js#L462
43
+ - https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/CompatRuntimeModule.js
22
44
  */
23
45
  class ChunkAssetPlugin {
24
46
  apply(compiler) {
25
- compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
26
- mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
27
- const chunkIdToName = chunk.getChunkMaps(false).name;
28
- const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
29
- chunkName,
30
- chunkId,
31
- ]));
32
- const buf = [source];
33
- buf.push('// function to get chunk asset');
34
- buf.push(
35
- // If chunkName is passed, we convert it to chunk asset url
36
- // .p => public path url ("/" or "/baseUrl/")
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
41
- //
42
- // Note: __webpack_require__.gca() is called in docusaurus.ts for
43
- // prefetching
44
- // Note: we previously used jsonpScriptSrc (Webpack 4)
45
- `__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
46
- return webpack_1.default.Template.asString(buf);
47
+ compiler.hooks.thisCompilation.tap(PluginName, (compilation) => {
48
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(PluginName, (chunk) => {
49
+ compilation.addRuntimeModule(chunk, new ChunkAssetRuntimeModule());
47
50
  });
48
51
  });
49
52
  }
50
53
  }
51
54
  exports.default = ChunkAssetPlugin;
55
+ // Inspired by https://github.com/webpack/webpack/blob/v5.94.0/lib/runtime/CompatRuntimeModule.js
56
+ class ChunkAssetRuntimeModule extends webpack_1.default.RuntimeModule {
57
+ constructor() {
58
+ super('ChunkAssetRuntimeModule', webpack_1.default.RuntimeModule.STAGE_ATTACH);
59
+ this.fullHash = true;
60
+ }
61
+ generate() {
62
+ return generateGetChunkAssetRuntimeCode(this.chunk);
63
+ }
64
+ }
@@ -33,8 +33,6 @@ async function createServerConfig(params) {
33
33
  path: outputDir,
34
34
  filename: outputFilename,
35
35
  libraryTarget: 'commonjs2',
36
- // Workaround for Webpack 4 Bug (https://github.com/webpack/webpack/issues/6522)
37
- globalObject: 'this',
38
36
  },
39
37
  plugins: [
40
38
  // Show compilation progress bar.
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-6068",
4
+ "version": "0.0.0-6072",
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-6068",
47
- "@docusaurus/logger": "0.0.0-6068",
48
- "@docusaurus/mdx-loader": "0.0.0-6068",
49
- "@docusaurus/utils": "0.0.0-6068",
50
- "@docusaurus/utils-common": "0.0.0-6068",
51
- "@docusaurus/utils-validation": "0.0.0-6068",
46
+ "@docusaurus/cssnano-preset": "0.0.0-6072",
47
+ "@docusaurus/logger": "0.0.0-6072",
48
+ "@docusaurus/mdx-loader": "0.0.0-6072",
49
+ "@docusaurus/utils": "0.0.0-6072",
50
+ "@docusaurus/utils-common": "0.0.0-6072",
51
+ "@docusaurus/utils-validation": "0.0.0-6072",
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-6068",
108
- "@docusaurus/types": "0.0.0-6068",
107
+ "@docusaurus/module-type-aliases": "0.0.0-6072",
108
+ "@docusaurus/types": "0.0.0-6072",
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": "4f0bc982b589965d7238334bb9b5bf6c483cc35a"
135
+ "gitHead": "0489236d6e7d2912ca71b3b251d155e30bb8cd4d"
136
136
  }