@docusaurus/utils 4.0.0-canary-6928 → 4.0.0-canary-6929

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.
@@ -64,10 +64,12 @@ export declare const DEFAULT_PORT: number;
64
64
  /** Default plugin ID. */
65
65
  export declare const DEFAULT_PLUGIN_ID = "default";
66
66
  /**
67
- * Allow overriding the limit after which the url loader will no longer inline
68
- * assets.
67
+ * Max size in bytes under which assets (images, fonts, medias) are inlined in
68
+ * the bundles as base64 data URLs, instead of being emitted as separate files.
69
+ * Overrides the default max size when the `DOCUSAURUS_ASSET_INLINE_MAX_SIZE`
70
+ * env variable is set.
69
71
  *
70
72
  * @see https://github.com/facebook/docusaurus/issues/5493
71
73
  */
72
- export declare const WEBPACK_URL_LOADER_LIMIT: string | number;
74
+ export declare const ASSET_INLINE_MAX_SIZE: number | undefined;
73
75
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AACF,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AAEF,+BAA+B;AAC/B,eAAO,MAAM,kBAAkB,QAE4B,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAC6B,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,WAAW,CAAC;AAEtD;;;GA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,EAAE,MAAM,GAAG,SAGhC,CAAC"}
package/lib/constants.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.DEFAULT_I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
9
+ exports.ASSET_INLINE_MAX_SIZE = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.DEFAULT_I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
10
  /** Node major version, directly read from env. */
11
11
  exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
12
12
  /** Node minor version, directly read from env. */
@@ -71,10 +71,15 @@ exports.DEFAULT_PORT = process.env.PORT
71
71
  /** Default plugin ID. */
72
72
  exports.DEFAULT_PLUGIN_ID = 'default';
73
73
  /**
74
- * Allow overriding the limit after which the url loader will no longer inline
75
- * assets.
74
+ * Max size in bytes under which assets (images, fonts, medias) are inlined in
75
+ * the bundles as base64 data URLs, instead of being emitted as separate files.
76
+ * Overrides the default max size when the `DOCUSAURUS_ASSET_INLINE_MAX_SIZE`
77
+ * env variable is set.
76
78
  *
77
79
  * @see https://github.com/facebook/docusaurus/issues/5493
78
80
  */
79
- exports.WEBPACK_URL_LOADER_LIMIT = process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
81
+ exports.ASSET_INLINE_MAX_SIZE = process.env
82
+ .DOCUSAURUS_ASSET_INLINE_MAX_SIZE
83
+ ? parseInt(process.env.DOCUSAURUS_ASSET_INLINE_MAX_SIZE, 10)
84
+ : undefined;
80
85
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,kDAAkD;AACrC,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,EACpC,EAAE,CACH,CAAC;AACF,kDAAkD;AACrC,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,EACpC,EAAE,CACH,CAAC;AAEF,+BAA+B;AAClB,QAAA,kBAAkB;AAC7B,iEAAiE;AAChE,OAAO,CAAC,iBAAiB,CAAuB,CAAC,OAAO,CAAC;AAE5D;;;GAGG;AACU,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C;;;;;;GAMG;AACU,QAAA,wBAAwB,GAAG,mBAAmB,CAAC;AAE5D,qDAAqD;AACxC,QAAA,sBAAsB,GACjC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,iBAAiB,CAAC;AAErE;;;GAGG;AACU,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,aAAa,CAAC;AAEnE;;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BAAwB,GAAG,mBAAmB,CAAC;AAE5D,qDAAqD;AACxC,QAAA,sBAAsB,GACjC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,iBAAiB,CAAC;AAErE;;;GAGG;AACU,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,aAAa,CAAC;AAEnE;;;GAGG;AACU,QAAA,YAAY,GAAG,KAAK,CAAC;AAElC;;;GAGG;AACU,QAAA,uBAAuB,GAAG,QAAQ,CAAC;AAEhD;;;GAGG;AACU,QAAA,6BAA6B,GAAG,QAAQ,CAAC;AAEtD;;;GAGG;AACU,QAAA,UAAU,GAAG,GAAG,QAAA,YAAY,QAAQ,CAAC;AAElD;;;GAGG;AACU,QAAA,qBAAqB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACU,QAAA,2BAA2B,GAAG,WAAW,CAAC;AAEvD,gDAAgD;AACnC,QAAA,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI;IAC1C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IAChC,CAAC,CAAC,IAAI,CAAC;AAET,yBAAyB;AACZ,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE3C;;;;;;;GAOG;AACU,QAAA,qBAAqB,GAAuB,OAAO,CAAC,GAAG;KACjE,gCAAgC;IACjC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,EAAE,CAAC;IAC5D,CAAC,CAAC,SAAS,CAAC"}
package/lib/index.d.ts CHANGED
@@ -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
- export { NODE_MAJOR_VERSION, NODE_MINOR_VERSION, DOCUSAURUS_VERSION, DEFAULT_BUILD_DIR_NAME, DEFAULT_CONFIG_FILE_NAME, BABEL_CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME, SRC_DIR_NAME, DEFAULT_STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, DEFAULT_I18N_DIR_NAME, CODE_TRANSLATIONS_FILE_NAME, DEFAULT_PORT, DEFAULT_PLUGIN_ID, WEBPACK_URL_LOADER_LIMIT, } from './constants';
7
+ export { NODE_MAJOR_VERSION, NODE_MINOR_VERSION, DOCUSAURUS_VERSION, DEFAULT_BUILD_DIR_NAME, DEFAULT_CONFIG_FILE_NAME, BABEL_CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME, SRC_DIR_NAME, DEFAULT_STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, DEFAULT_I18N_DIR_NAME, CODE_TRANSLATIONS_FILE_NAME, DEFAULT_PORT, DEFAULT_PLUGIN_ID, ASSET_INLINE_MAX_SIZE, } from './constants';
8
8
  export { generate, readOutputHTMLFile } from './emitUtils';
9
9
  export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, getLocaleConfig, } from './i18nUtils';
10
10
  export { mapAsyncSequential, findAsyncSequential } from './jsUtils';
@@ -17,7 +17,7 @@ export { type ContentPaths, type SourceToPermalink, resolveMarkdownLinkPathname,
17
17
  export { type SluggerOptions, type Slugger, createSlugger } from './slugger';
18
18
  export { isNameTooLong, shortName, posixPath, toMessageRelativeFilePath, aliasedSitePath, aliasedSitePathToRelativePath, escapePath, addTrailingPathSeparator, } from './pathUtils';
19
19
  export { md5Hash, simpleHash, docuHash } from './hashUtils';
20
- export { getFileLoaderUtils, getWebpackLoaderCompilerName, type WebpackCompilerName, } from './webpackUtils';
20
+ export { getAssetRuleUtils, findAssetRule, createAssetRequest, getWebpackLoaderCompilerName, type AssetRequestType, type WebpackCompilerName, } from './webpackUtils';
21
21
  export { loadFreshModule } from './moduleUtils';
22
22
  export { getDataFilePath, readDataFile, getContentPathList, findFolderContainingFile, getFolderContainingFile, } from './dataFileUtils';
23
23
  export { isDraft, isUnlisted } from './contentVisibilityUtils';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,kBAAkB,EAAE,mBAAmB,EAAC,MAAM,WAAW,CAAC;AAClE,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EACL,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,mBAAmB,EACnB,+BAA+B,EAC/B,aAAa,EACb,0BAA0B,EAC1B,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,eAAe,EAC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O,EACL,aAAa,EACb,SAAS,EACT,SAAS,EACT,yBAAyB,EACzB,eAAe,EACf,6BAA6B,EAC7B,UAAU,EACV,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,4BAA4B,EAC5B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EACL,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAE3C,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,QAAQ,CAAC"}
package/lib/index.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.resolveMarkdownLinkPathname = exports.writeMarkdownHeadingId = exports.escapeMarkdownHeadingIds = exports.parseMarkdownHeadingId = exports.parseMarkdownFile = exports.parseMarkdownContentTitle = exports.DEFAULT_PARSE_FRONT_MATTER = exports.createExcerpt = exports.admonitionTitleToDirectiveLabel = exports.unwrapMdxCodeBlocks = exports.getTagVisibility = exports.groupTaggedItems = exports.buildSshUrl = exports.buildHttpsUrl = exports.hasSSHProtocol = exports.serializeURLPath = exports.toURLPath = exports.parseURLOrPath = exports.parseLocalURLPath = exports.parseURLPath = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = exports.findAsyncSequential = exports.mapAsyncSequential = exports.getLocaleConfig = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = exports.readOutputHTMLFile = exports.generate = exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.DEFAULT_I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
- exports.reportInlineTags = exports.normalizeTags = exports.TEST_VCS = exports.getVcsPreset = exports.VcsPresetNames = exports.readLastUpdateData = exports.flattenRoutes = exports.isUnlisted = exports.isDraft = exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.readDataFile = exports.getDataFilePath = exports.loadFreshModule = exports.getWebpackLoaderCompilerName = exports.getFileLoaderUtils = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePathToRelativePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = void 0;
9
+ exports.resolveMarkdownLinkPathname = exports.writeMarkdownHeadingId = exports.escapeMarkdownHeadingIds = exports.parseMarkdownHeadingId = exports.parseMarkdownFile = exports.parseMarkdownContentTitle = exports.DEFAULT_PARSE_FRONT_MATTER = exports.createExcerpt = exports.admonitionTitleToDirectiveLabel = exports.unwrapMdxCodeBlocks = exports.getTagVisibility = exports.groupTaggedItems = exports.buildSshUrl = exports.buildHttpsUrl = exports.hasSSHProtocol = exports.serializeURLPath = exports.toURLPath = exports.parseURLOrPath = exports.parseLocalURLPath = exports.parseURLPath = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = exports.findAsyncSequential = exports.mapAsyncSequential = exports.getLocaleConfig = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = exports.readOutputHTMLFile = exports.generate = exports.ASSET_INLINE_MAX_SIZE = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.DEFAULT_I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
+ exports.reportInlineTags = exports.normalizeTags = exports.TEST_VCS = exports.getVcsPreset = exports.VcsPresetNames = exports.readLastUpdateData = exports.flattenRoutes = exports.isUnlisted = exports.isDraft = exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.readDataFile = exports.getDataFilePath = exports.loadFreshModule = exports.getWebpackLoaderCompilerName = exports.createAssetRequest = exports.findAssetRule = exports.getAssetRuleUtils = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePathToRelativePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = void 0;
11
11
  var constants_1 = require("./constants");
12
12
  Object.defineProperty(exports, "NODE_MAJOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MAJOR_VERSION; } });
13
13
  Object.defineProperty(exports, "NODE_MINOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MINOR_VERSION; } });
@@ -24,7 +24,7 @@ Object.defineProperty(exports, "DEFAULT_I18N_DIR_NAME", { enumerable: true, get:
24
24
  Object.defineProperty(exports, "CODE_TRANSLATIONS_FILE_NAME", { enumerable: true, get: function () { return constants_1.CODE_TRANSLATIONS_FILE_NAME; } });
25
25
  Object.defineProperty(exports, "DEFAULT_PORT", { enumerable: true, get: function () { return constants_1.DEFAULT_PORT; } });
26
26
  Object.defineProperty(exports, "DEFAULT_PLUGIN_ID", { enumerable: true, get: function () { return constants_1.DEFAULT_PLUGIN_ID; } });
27
- Object.defineProperty(exports, "WEBPACK_URL_LOADER_LIMIT", { enumerable: true, get: function () { return constants_1.WEBPACK_URL_LOADER_LIMIT; } });
27
+ Object.defineProperty(exports, "ASSET_INLINE_MAX_SIZE", { enumerable: true, get: function () { return constants_1.ASSET_INLINE_MAX_SIZE; } });
28
28
  var emitUtils_1 = require("./emitUtils");
29
29
  Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return emitUtils_1.generate; } });
30
30
  Object.defineProperty(exports, "readOutputHTMLFile", { enumerable: true, get: function () { return emitUtils_1.readOutputHTMLFile; } });
@@ -83,7 +83,9 @@ Object.defineProperty(exports, "md5Hash", { enumerable: true, get: function () {
83
83
  Object.defineProperty(exports, "simpleHash", { enumerable: true, get: function () { return hashUtils_1.simpleHash; } });
84
84
  Object.defineProperty(exports, "docuHash", { enumerable: true, get: function () { return hashUtils_1.docuHash; } });
85
85
  var webpackUtils_1 = require("./webpackUtils");
86
- Object.defineProperty(exports, "getFileLoaderUtils", { enumerable: true, get: function () { return webpackUtils_1.getFileLoaderUtils; } });
86
+ Object.defineProperty(exports, "getAssetRuleUtils", { enumerable: true, get: function () { return webpackUtils_1.getAssetRuleUtils; } });
87
+ Object.defineProperty(exports, "findAssetRule", { enumerable: true, get: function () { return webpackUtils_1.findAssetRule; } });
88
+ Object.defineProperty(exports, "createAssetRequest", { enumerable: true, get: function () { return webpackUtils_1.createAssetRequest; } });
87
89
  Object.defineProperty(exports, "getWebpackLoaderCompilerName", { enumerable: true, get: function () { return webpackUtils_1.getWebpackLoaderCompilerName; } });
88
90
  var moduleUtils_1 = require("./moduleUtils");
89
91
  Object.defineProperty(exports, "loadFreshModule", { enumerable: true, get: function () { return moduleUtils_1.loadFreshModule; } });
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yCAiBqB;AAhBnB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,yGAAA,YAAY,OAAA;AACZ,oHAAA,uBAAuB,OAAA;AACvB,0HAAA,6BAA6B,OAAA;AAC7B,uGAAA,UAAU,OAAA;AACV,kHAAA,qBAAqB,OAAA;AACrB,wHAAA,2BAA2B,OAAA;AAC3B,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AAE1B,yCAAyD;AAAjD,qGAAA,QAAQ,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AACpC,yCAKqB;AAJnB,8GAAA,iBAAiB,OAAA;AACjB,0HAAA,6BAA6B,OAAA;AAC7B,8GAAA,iBAAiB,OAAA;AACjB,4GAAA,eAAe,OAAA;AAEjB,qCAAkE;AAA1D,6GAAA,kBAAkB,OAAA;AAAE,8GAAA,mBAAmB,OAAA;AAC/C,uCAeoB;AAdlB,wGAAA,YAAY,OAAA;AACZ,sGAAA,UAAU,OAAA;AACV,sGAAA,UAAU,OAAA;AACV,sGAAA,UA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A;AACf,6GAAA,YAAY,OAAA;AACZ,mHAAA,kBAAkB,OAAA;AAClB,yHAAA,wBAAwB,OAAA;AACxB,wHAAA,uBAAuB,OAAA;AAEzB,mEAA6D;AAArD,iHAAA,OAAO,OAAA;AAAE,oHAAA,UAAU,OAAA;AAC3B,2CAA2C;AAAnC,2GAAA,aAAa,OAAA;AAErB,qDAI2B;AAHzB,qHAAA,kBAAkB,OAAA;AAKpB,iCAAiE;AAAzD,qGAAA,cAAc,OAAA;AAAE,mGAAA,YAAY,OAAA;AAAE,+FAAA,QAAQ,OAAA;AAE9C,+BAAuD;AAA/C,qGAAA,aAAa,OAAA;AAAE,wGAAA,gBAAgB,OAAA"}
@@ -7,20 +7,37 @@
7
7
  import type { RuleSetRule, LoaderContext } from 'webpack';
8
8
  export type WebpackCompilerName = 'server' | 'client';
9
9
  export declare function getWebpackLoaderCompilerName(context: LoaderContext<unknown>): WebpackCompilerName;
10
- type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
11
- type FileLoaderUtils = {
12
- loaders: {
13
- file: (options: {
14
- folder: AssetFolder;
15
- }) => RuleSetRule;
16
- url: (options: {
17
- folder: AssetFolder;
18
- }) => RuleSetRule;
19
- inlineMarkdownImageFileLoader: string;
20
- inlineMarkdownAssetImageFileLoader: string;
21
- inlineMarkdownLinkFileLoader: string;
22
- };
10
+ /**
11
+ * How an asset request created with `createAssetRequest()` is handled:
12
+ * - `image`: emitted as an image file, or inlined as a data URL if small
13
+ * - `image-file`: always emitted as an image file, never inlined
14
+ * - `file`: always emitted as a file, whatever its extension
15
+ */
16
+ export type AssetRequestType = 'image' | 'image-file' | 'file';
17
+ /**
18
+ * Creates a request that always resolves to an asset URL string, for
19
+ * Docusaurus-generated code (Markdown images, links, front matter assets...).
20
+ *
21
+ * The `!` prefix disables the configured normal loaders, and the resource query
22
+ * selects a dedicated asset rule. This way, other plugins (ideal-image,
23
+ * SVGR...) do not transform those assets.
24
+ * See https://webpack.js.org/concepts/loaders/#inline
25
+ *
26
+ * @param assetPath the already escaped asset path to require
27
+ * @param search an optional user-provided query string, starting with `?`
28
+ */
29
+ export declare function createAssetRequest({ assetPath, search, type, }: {
30
+ assetPath: string;
31
+ search?: string;
32
+ type: AssetRequestType;
33
+ }): string;
34
+ type AssetRuleUtils = {
23
35
  rules: {
36
+ /**
37
+ * The single rule handling all assets, made of the rules below.
38
+ * It is a `oneOf` rule: the first matching child rule wins.
39
+ */
40
+ assets: () => RuleSetRule;
24
41
  images: () => RuleSetRule;
25
42
  svgs: () => RuleSetRule;
26
43
  fonts: () => RuleSetRule;
@@ -29,9 +46,20 @@ type FileLoaderUtils = {
29
46
  };
30
47
  };
31
48
  /**
32
- * Returns unified loader configurations to be used for various file types.
49
+ * Returns the bundler asset module rules to be used for various file types.
33
50
  * Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
34
51
  */
35
- export declare function getFileLoaderUtils(isServer: boolean): FileLoaderUtils;
52
+ export declare function getAssetRuleUtils(isServer: boolean): AssetRuleUtils;
53
+ /**
54
+ * Finds a rule in the asset `oneOf` rule, so that plugins can enhance it.
55
+ * The rule is found by comparing its `test` condition.
56
+ */
57
+ export declare function findAssetRule({ rules, test, }: {
58
+ rules: RuleSetRule[];
59
+ test: RuleSetRule['test'];
60
+ }): {
61
+ parentRules: RuleSetRule[];
62
+ rule: RuleSetRule;
63
+ } | undefined;
36
64
  export {};
37
65
  //# sourceMappingURL=webpackUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpackUtils.d.ts","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,WAAW,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAExD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEtD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,aAAa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ACL,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;CACxB,GAAG,MAAM,CAGT;AAED,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE;QACL;;;WAGG;QACH,MAAM,EAAE,MAAM,WAAW,CAAC;QAC1B,MAAM,EAAE,MAAM,WAAW,CAAC;QAC1B,IAAI,EAAE,MAAM,WAAW,CAAC;QACxB,KAAK,EAAE,MAAM,WAAW,CAAC;QACzB,KAAK,EAAE,MAAM,WAAW,CAAC;QACzB,WAAW,EAAE,MAAM,WAAW,CAAC;KAChC,CAAC;CACH,CAAC;AAyFF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,GAAG,cAAc,CAEnE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,IAAI,GACL,EAAE;IACD,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC3B,GAAG;IAAC,WAAW,EAAE,WAAW,EAAE,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAC,GAAG,SAAS,CAgB9D"}
@@ -7,10 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getWebpackLoaderCompilerName = getWebpackLoaderCompilerName;
10
- exports.getFileLoaderUtils = getFileLoaderUtils;
10
+ exports.createAssetRequest = createAssetRequest;
11
+ exports.getAssetRuleUtils = getAssetRuleUtils;
12
+ exports.findAssetRule = findAssetRule;
11
13
  const tslib_1 = require("tslib");
12
14
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
13
- const pathUtils_1 = require("./pathUtils");
14
15
  const constants_1 = require("./constants");
15
16
  function getWebpackLoaderCompilerName(context) {
16
17
  const compilerName = context._compiler?.name;
@@ -22,90 +23,117 @@ function getWebpackLoaderCompilerName(context) {
22
23
  throw new Error(`Cannot get valid Docusaurus webpack compiler name. Found compilerName=${compilerName}`);
23
24
  }
24
25
  }
25
- // TODO this historical code is quite messy
26
- // We should try to get rid of it and move to assets pipeline
27
- function createFileLoaderUtils({ isServer, }) {
28
- // Files/images < urlLoaderLimit will be inlined as base64 strings directly in
29
- // the html
30
- const urlLoaderLimit = constants_1.WEBPACK_URL_LOADER_LIMIT;
31
- const fileLoaderFileName = (folder) => node_path_1.default.posix.join(constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME, folder, '[name]-[contenthash].[ext]');
32
- const loaders = {
33
- file: (options) => ({
34
- loader: require.resolve(`file-loader`),
35
- options: {
36
- name: fileLoaderFileName(options.folder),
37
- emitFile: !isServer,
38
- },
39
- }),
40
- url: (options) => ({
41
- loader: require.resolve('url-loader'),
42
- options: {
43
- limit: urlLoaderLimit,
44
- name: fileLoaderFileName(options.folder),
45
- fallback: require.resolve('file-loader'),
46
- emitFile: !isServer,
47
- },
48
- }),
49
- // TODO avoid conflicts with the ideal-image plugin
50
- // TODO this may require a little breaking change for ideal-image users?
51
- // Maybe with the ideal image plugin, all md images should be "ideal"?
52
- // This is used to force url-loader+file-loader on markdown images
53
- // https://webpack.js.org/concepts/loaders/#inline
54
- inlineMarkdownImageFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('url-loader'))}?limit=${urlLoaderLimit}&name=${fileLoaderFileName('images')}&fallback=${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}${isServer ? `&emitFile=false` : ''}!`,
55
- inlineMarkdownAssetImageFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}?name=${fileLoaderFileName('images')}${isServer ? `&emitFile=false` : ''}!`,
56
- inlineMarkdownLinkFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}?name=${fileLoaderFileName('files')}${isServer ? `&emitFile=false` : ''}!`,
57
- };
58
- const notTextImport = { type: { not: 'text' } };
26
+ const AssetRequestQueryParam = 'docusaurus-asset';
27
+ /**
28
+ * Creates a request that always resolves to an asset URL string, for
29
+ * Docusaurus-generated code (Markdown images, links, front matter assets...).
30
+ *
31
+ * The `!` prefix disables the configured normal loaders, and the resource query
32
+ * selects a dedicated asset rule. This way, other plugins (ideal-image,
33
+ * SVGR...) do not transform those assets.
34
+ * See https://webpack.js.org/concepts/loaders/#inline
35
+ *
36
+ * @param assetPath the already escaped asset path to require
37
+ * @param search an optional user-provided query string, starting with `?`
38
+ */
39
+ function createAssetRequest({ assetPath, search, type, }) {
40
+ const query = `${AssetRequestQueryParam}=${type}`;
41
+ return `!${assetPath}${search ? `${search}&${query}` : `?${query}`}`;
42
+ }
43
+ function createAssetRuleUtils({ isServer }) {
44
+ const generator = (folder) => ({
45
+ filename: node_path_1.default.posix.join(constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME, folder, '[name]-[contenthash][ext]'),
46
+ // The server compilation does not need to emit assets
47
+ emit: !isServer,
48
+ });
49
+ // An asset emitted as a file, or inlined as a data URL if small enough
50
+ const asset = (folder) => ({
51
+ type: 'asset',
52
+ parser: { dataUrlCondition: { maxSize: constants_1.ASSET_INLINE_MAX_SIZE ?? 10000 } },
53
+ generator: generator(folder),
54
+ });
55
+ // An asset always emitted as a file
56
+ const assetResource = (folder) => ({
57
+ type: 'asset/resource',
58
+ generator: generator(folder),
59
+ });
60
+ const assetRequestRule = (type, rule) => ({
61
+ resourceQuery: new RegExp(`[?&]${AssetRequestQueryParam}=${type}(?:&|$)`),
62
+ ...rule,
63
+ });
59
64
  const rules = {
60
- /**
61
- * Loads image assets, inlines images via a data URI if they are below
62
- * the size threshold
63
- */
65
+ assets: () => ({
66
+ with: { type: { not: 'text' } },
67
+ oneOf: [
68
+ // Requests created with createAssetRequest() come first on purpose
69
+ // They must not be handled by other asset rules (ideal-image, SVGR...)
70
+ assetRequestRule('image', asset('images')),
71
+ assetRequestRule('image-file', assetResource('images')),
72
+ assetRequestRule('file', assetResource('files')),
73
+ rules.images(),
74
+ rules.svgs(),
75
+ rules.fonts(),
76
+ rules.media(),
77
+ rules.otherAssets(),
78
+ ],
79
+ }),
64
80
  images: () => ({
65
- use: [loaders.url({ folder: 'images' })],
66
- test: /\.(?:ico|jpe?g|png|gif|webp|avif)(?:\?.*)?$/i,
67
- with: notTextImport,
81
+ test: /\.(?:ico|jpe?g|png|gif|webp|avif)$/i,
82
+ ...asset('images'),
68
83
  }),
69
84
  /**
70
85
  * The SVG rule is isolated on purpose: our SVGR plugin enhances it
71
86
  * See https://github.com/facebook/docusaurus/pull/10820
72
87
  */
73
88
  svgs: () => ({
74
- use: [loaders.url({ folder: 'images' })],
75
89
  test: /\.svg$/i,
76
- with: notTextImport,
90
+ ...asset('images'),
77
91
  }),
78
92
  fonts: () => ({
79
- use: [loaders.url({ folder: 'fonts' })],
80
93
  test: /\.(?:woff2?|eot|ttf|otf)$/i,
81
- with: notTextImport,
94
+ ...asset('fonts'),
82
95
  }),
83
- /**
84
- * Loads audio and video and inlines them via a data URI if they are below
85
- * the size threshold
86
- */
87
96
  media: () => ({
88
- use: [loaders.url({ folder: 'medias' })],
89
97
  test: /\.(?:mp4|avi|mov|mkv|mpg|mpeg|vob|wmv|m4v|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
90
- with: notTextImport,
98
+ ...asset('medias'),
91
99
  }),
92
100
  otherAssets: () => ({
93
- use: [loaders.file({ folder: 'files' })],
94
101
  test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,
95
- with: notTextImport,
102
+ ...assetResource('files'),
96
103
  }),
97
104
  };
98
- return { loaders, rules };
105
+ return { rules };
99
106
  }
100
- const FileLoaderUtilsMap = {
101
- server: createFileLoaderUtils({ isServer: true }),
102
- client: createFileLoaderUtils({ isServer: false }),
107
+ const AssetRuleUtilsMap = {
108
+ server: createAssetRuleUtils({ isServer: true }),
109
+ client: createAssetRuleUtils({ isServer: false }),
103
110
  };
104
111
  /**
105
- * Returns unified loader configurations to be used for various file types.
112
+ * Returns the bundler asset module rules to be used for various file types.
106
113
  * Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
107
114
  */
108
- function getFileLoaderUtils(isServer) {
109
- return isServer ? FileLoaderUtilsMap.server : FileLoaderUtilsMap.client;
115
+ function getAssetRuleUtils(isServer) {
116
+ return isServer ? AssetRuleUtilsMap.server : AssetRuleUtilsMap.client;
117
+ }
118
+ /**
119
+ * Finds a rule in the asset `oneOf` rule, so that plugins can enhance it.
120
+ * The rule is found by comparing its `test` condition.
121
+ */
122
+ function findAssetRule({ rules, test, }) {
123
+ for (const rule of rules) {
124
+ if (String(rule.test) === String(test)) {
125
+ return { parentRules: rules, rule };
126
+ }
127
+ if (rule.oneOf) {
128
+ const result = findAssetRule({
129
+ rules: rule.oneOf,
130
+ test,
131
+ });
132
+ if (result) {
133
+ return result;
134
+ }
135
+ }
136
+ }
137
+ return undefined;
110
138
  }
111
139
  //# sourceMappingURL=webpackUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kEAA6B;AAC7B,2CAAuC;AACvC,2CAGqB;AAKrB,sCACE,OAA+B;IAE/B,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;IAC7C,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC;QACtB;YACE,MAAM,IAAI,KAAK,CACb,yEAAyE,YAAY,EAAE,CACxF,CAAC;IACN,CAAC;AACH,CAAC;AAqBD,2CAA2C;AAC3C,8DAA8D;AAC9D,SAAS,qBAAqB,CAAC,EAC7B,QAAQ,GAGT;IACC,8EAA8E;IAC9E,WAAW;IACX,MAAM,cAAc,GAAG,oCAAwB,CAAC;IAEhD,MAAM,kBAAkB,GAAG,CAAC,MAAmB,EAAE,EAAE,CACj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;QACzB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,OAAO,EAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,aAAa,CAAC;gBAC3B,KAAK,EAAE,IAAI,CAAC,KAAsB;gBAClC,IAAI;aACL,CAAC,CAAC;YACH,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/utils",
3
- "version": "4.0.0-canary-6928",
3
+ "version": "4.0.0-canary-6929",
4
4
  "description": "Node utility functions for Docusaurus packages.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -15,11 +15,10 @@
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
17
  "@11ty/gray-matter": "^3.0.0",
18
- "@docusaurus/fs": "4.0.0-canary-6928",
19
- "@docusaurus/logger": "4.0.0-canary-6928",
20
- "@docusaurus/types": "4.0.0-canary-6928",
18
+ "@docusaurus/fs": "4.0.0-canary-6929",
19
+ "@docusaurus/logger": "4.0.0-canary-6929",
20
+ "@docusaurus/types": "4.0.0-canary-6929",
21
21
  "execa": "^10.0.1",
22
- "file-loader": "^6.2.0",
23
22
  "github-slugger": "^2.0.0",
24
23
  "jiti": "^2.7.0",
25
24
  "js-yaml": "^5.4.1",
@@ -27,7 +26,6 @@
27
26
  "p-queue": "^9.3.3",
28
27
  "resolve-pathname": "^3.0.0",
29
28
  "tslib": "^2.8.1",
30
- "url-loader": "^4.1.1",
31
29
  "utility-types": "^3.11.0",
32
30
  "webpack": "^5.111.0"
33
31
  },
package/src/constants.ts CHANGED
@@ -91,10 +91,14 @@ export const DEFAULT_PORT = process.env.PORT
91
91
  export const DEFAULT_PLUGIN_ID = 'default';
92
92
 
93
93
  /**
94
- * Allow overriding the limit after which the url loader will no longer inline
95
- * assets.
94
+ * Max size in bytes under which assets (images, fonts, medias) are inlined in
95
+ * the bundles as base64 data URLs, instead of being emitted as separate files.
96
+ * Overrides the default max size when the `DOCUSAURUS_ASSET_INLINE_MAX_SIZE`
97
+ * env variable is set.
96
98
  *
97
99
  * @see https://github.com/facebook/docusaurus/issues/5493
98
100
  */
99
- export const WEBPACK_URL_LOADER_LIMIT =
100
- process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
101
+ export const ASSET_INLINE_MAX_SIZE: number | undefined = process.env
102
+ .DOCUSAURUS_ASSET_INLINE_MAX_SIZE
103
+ ? parseInt(process.env.DOCUSAURUS_ASSET_INLINE_MAX_SIZE, 10)
104
+ : undefined;
package/src/index.ts CHANGED
@@ -21,7 +21,7 @@ export {
21
21
  CODE_TRANSLATIONS_FILE_NAME,
22
22
  DEFAULT_PORT,
23
23
  DEFAULT_PLUGIN_ID,
24
- WEBPACK_URL_LOADER_LIMIT,
24
+ ASSET_INLINE_MAX_SIZE,
25
25
  } from './constants';
26
26
  export {generate, readOutputHTMLFile} from './emitUtils';
27
27
  export {
@@ -93,8 +93,11 @@ export {
93
93
  } from './pathUtils';
94
94
  export {md5Hash, simpleHash, docuHash} from './hashUtils';
95
95
  export {
96
- getFileLoaderUtils,
96
+ getAssetRuleUtils,
97
+ findAssetRule,
98
+ createAssetRequest,
97
99
  getWebpackLoaderCompilerName,
100
+ type AssetRequestType,
98
101
  type WebpackCompilerName,
99
102
  } from './webpackUtils';
100
103
  export {loadFreshModule} from './moduleUtils';
@@ -6,9 +6,8 @@
6
6
  */
7
7
 
8
8
  import path from 'node:path';
9
- import {escapePath} from './pathUtils';
10
9
  import {
11
- WEBPACK_URL_LOADER_LIMIT,
10
+ ASSET_INLINE_MAX_SIZE,
12
11
  OUTPUT_STATIC_ASSETS_DIR_NAME,
13
12
  } from './constants';
14
13
  import type {RuleSetRule, LoaderContext} from 'webpack';
@@ -32,15 +31,48 @@ export function getWebpackLoaderCompilerName(
32
31
 
33
32
  type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
34
33
 
35
- type FileLoaderUtils = {
36
- loaders: {
37
- file: (options: {folder: AssetFolder}) => RuleSetRule;
38
- url: (options: {folder: AssetFolder}) => RuleSetRule;
39
- inlineMarkdownImageFileLoader: string;
40
- inlineMarkdownAssetImageFileLoader: string;
41
- inlineMarkdownLinkFileLoader: string;
42
- };
34
+ /**
35
+ * How an asset request created with `createAssetRequest()` is handled:
36
+ * - `image`: emitted as an image file, or inlined as a data URL if small
37
+ * - `image-file`: always emitted as an image file, never inlined
38
+ * - `file`: always emitted as a file, whatever its extension
39
+ */
40
+ export type AssetRequestType = 'image' | 'image-file' | 'file';
41
+
42
+ const AssetRequestQueryParam = 'docusaurus-asset';
43
+
44
+ /**
45
+ * Creates a request that always resolves to an asset URL string, for
46
+ * Docusaurus-generated code (Markdown images, links, front matter assets...).
47
+ *
48
+ * The `!` prefix disables the configured normal loaders, and the resource query
49
+ * selects a dedicated asset rule. This way, other plugins (ideal-image,
50
+ * SVGR...) do not transform those assets.
51
+ * See https://webpack.js.org/concepts/loaders/#inline
52
+ *
53
+ * @param assetPath the already escaped asset path to require
54
+ * @param search an optional user-provided query string, starting with `?`
55
+ */
56
+ export function createAssetRequest({
57
+ assetPath,
58
+ search,
59
+ type,
60
+ }: {
61
+ assetPath: string;
62
+ search?: string;
63
+ type: AssetRequestType;
64
+ }): string {
65
+ const query = `${AssetRequestQueryParam}=${type}`;
66
+ return `!${assetPath}${search ? `${search}&${query}` : `?${query}`}`;
67
+ }
68
+
69
+ type AssetRuleUtils = {
43
70
  rules: {
71
+ /**
72
+ * The single rule handling all assets, made of the rules below.
73
+ * It is a `oneOf` rule: the first matching child rule wins.
74
+ */
75
+ assets: () => RuleSetRule;
44
76
  images: () => RuleSetRule;
45
77
  svgs: () => RuleSetRule;
46
78
  fonts: () => RuleSetRule;
@@ -49,77 +81,58 @@ type FileLoaderUtils = {
49
81
  };
50
82
  };
51
83
 
52
- // TODO this historical code is quite messy
53
- // We should try to get rid of it and move to assets pipeline
54
- function createFileLoaderUtils({
55
- isServer,
56
- }: {
57
- isServer: boolean;
58
- }): FileLoaderUtils {
59
- // Files/images < urlLoaderLimit will be inlined as base64 strings directly in
60
- // the html
61
- const urlLoaderLimit = WEBPACK_URL_LOADER_LIMIT;
62
-
63
- const fileLoaderFileName = (folder: AssetFolder) =>
64
- path.posix.join(
84
+ function createAssetRuleUtils({isServer}: {isServer: boolean}): AssetRuleUtils {
85
+ const generator = (folder: AssetFolder) => ({
86
+ filename: path.posix.join(
65
87
  OUTPUT_STATIC_ASSETS_DIR_NAME,
66
88
  folder,
67
- '[name]-[contenthash].[ext]',
68
- );
69
-
70
- const loaders: FileLoaderUtils['loaders'] = {
71
- file: (options: {folder: AssetFolder}) => ({
72
- loader: require.resolve(`file-loader`),
73
- options: {
74
- name: fileLoaderFileName(options.folder),
75
- emitFile: !isServer,
76
- },
89
+ '[name]-[contenthash][ext]',
90
+ ),
91
+ // The server compilation does not need to emit assets
92
+ emit: !isServer,
93
+ });
94
+
95
+ // An asset emitted as a file, or inlined as a data URL if small enough
96
+ const asset = (folder: AssetFolder): RuleSetRule => ({
97
+ type: 'asset',
98
+ parser: {dataUrlCondition: {maxSize: ASSET_INLINE_MAX_SIZE ?? 10000}},
99
+ generator: generator(folder),
100
+ });
101
+
102
+ // An asset always emitted as a file
103
+ const assetResource = (folder: AssetFolder): RuleSetRule => ({
104
+ type: 'asset/resource',
105
+ generator: generator(folder),
106
+ });
107
+
108
+ const assetRequestRule = (
109
+ type: AssetRequestType,
110
+ rule: RuleSetRule,
111
+ ): RuleSetRule => ({
112
+ resourceQuery: new RegExp(`[?&]${AssetRequestQueryParam}=${type}(?:&|$)`),
113
+ ...rule,
114
+ });
115
+
116
+ const rules: AssetRuleUtils['rules'] = {
117
+ assets: () => ({
118
+ with: {type: {not: 'text'}},
119
+ oneOf: [
120
+ // Requests created with createAssetRequest() come first on purpose
121
+ // They must not be handled by other asset rules (ideal-image, SVGR...)
122
+ assetRequestRule('image', asset('images')),
123
+ assetRequestRule('image-file', assetResource('images')),
124
+ assetRequestRule('file', assetResource('files')),
125
+ rules.images(),
126
+ rules.svgs(),
127
+ rules.fonts(),
128
+ rules.media(),
129
+ rules.otherAssets(),
130
+ ],
77
131
  }),
78
- url: (options: {folder: AssetFolder}) => ({
79
- loader: require.resolve('url-loader'),
80
- options: {
81
- limit: urlLoaderLimit,
82
- name: fileLoaderFileName(options.folder),
83
- fallback: require.resolve('file-loader'),
84
- emitFile: !isServer,
85
- },
86
- }),
87
-
88
- // TODO avoid conflicts with the ideal-image plugin
89
- // TODO this may require a little breaking change for ideal-image users?
90
- // Maybe with the ideal image plugin, all md images should be "ideal"?
91
- // This is used to force url-loader+file-loader on markdown images
92
- // https://webpack.js.org/concepts/loaders/#inline
93
- inlineMarkdownImageFileLoader: `!${escapePath(
94
- require.resolve('url-loader'),
95
- )}?limit=${urlLoaderLimit}&name=${fileLoaderFileName(
96
- 'images',
97
- )}&fallback=${escapePath(require.resolve('file-loader'))}${
98
- isServer ? `&emitFile=false` : ''
99
- }!`,
100
- inlineMarkdownAssetImageFileLoader: `!${escapePath(
101
- require.resolve('file-loader'),
102
- )}?name=${fileLoaderFileName('images')}${
103
- isServer ? `&emitFile=false` : ''
104
- }!`,
105
- inlineMarkdownLinkFileLoader: `!${escapePath(
106
- require.resolve('file-loader'),
107
- )}?name=${fileLoaderFileName('files')}${
108
- isServer ? `&emitFile=false` : ''
109
- }!`,
110
- };
111
-
112
- const notTextImport: RuleSetRule['with'] = {type: {not: 'text'}};
113
132
 
114
- const rules: FileLoaderUtils['rules'] = {
115
- /**
116
- * Loads image assets, inlines images via a data URI if they are below
117
- * the size threshold
118
- */
119
133
  images: () => ({
120
- use: [loaders.url({folder: 'images'})],
121
- test: /\.(?:ico|jpe?g|png|gif|webp|avif)(?:\?.*)?$/i,
122
- with: notTextImport,
134
+ test: /\.(?:ico|jpe?g|png|gif|webp|avif)$/i,
135
+ ...asset('images'),
123
136
  }),
124
137
 
125
138
  /**
@@ -127,46 +140,66 @@ function createFileLoaderUtils({
127
140
  * See https://github.com/facebook/docusaurus/pull/10820
128
141
  */
129
142
  svgs: () => ({
130
- use: [loaders.url({folder: 'images'})],
131
143
  test: /\.svg$/i,
132
- with: notTextImport,
144
+ ...asset('images'),
133
145
  }),
134
146
 
135
147
  fonts: () => ({
136
- use: [loaders.url({folder: 'fonts'})],
137
148
  test: /\.(?:woff2?|eot|ttf|otf)$/i,
138
- with: notTextImport,
149
+ ...asset('fonts'),
139
150
  }),
140
151
 
141
- /**
142
- * Loads audio and video and inlines them via a data URI if they are below
143
- * the size threshold
144
- */
145
152
  media: () => ({
146
- use: [loaders.url({folder: 'medias'})],
147
153
  test: /\.(?:mp4|avi|mov|mkv|mpg|mpeg|vob|wmv|m4v|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
148
- with: notTextImport,
154
+ ...asset('medias'),
149
155
  }),
150
156
 
151
157
  otherAssets: () => ({
152
- use: [loaders.file({folder: 'files'})],
153
158
  test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,
154
- with: notTextImport,
159
+ ...assetResource('files'),
155
160
  }),
156
161
  };
157
162
 
158
- return {loaders, rules};
163
+ return {rules};
159
164
  }
160
165
 
161
- const FileLoaderUtilsMap = {
162
- server: createFileLoaderUtils({isServer: true}),
163
- client: createFileLoaderUtils({isServer: false}),
166
+ const AssetRuleUtilsMap = {
167
+ server: createAssetRuleUtils({isServer: true}),
168
+ client: createAssetRuleUtils({isServer: false}),
164
169
  };
165
170
 
166
171
  /**
167
- * Returns unified loader configurations to be used for various file types.
172
+ * Returns the bundler asset module rules to be used for various file types.
168
173
  * Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
169
174
  */
170
- export function getFileLoaderUtils(isServer: boolean): FileLoaderUtils {
171
- return isServer ? FileLoaderUtilsMap.server : FileLoaderUtilsMap.client;
175
+ export function getAssetRuleUtils(isServer: boolean): AssetRuleUtils {
176
+ return isServer ? AssetRuleUtilsMap.server : AssetRuleUtilsMap.client;
177
+ }
178
+
179
+ /**
180
+ * Finds a rule in the asset `oneOf` rule, so that plugins can enhance it.
181
+ * The rule is found by comparing its `test` condition.
182
+ */
183
+ export function findAssetRule({
184
+ rules,
185
+ test,
186
+ }: {
187
+ rules: RuleSetRule[];
188
+ test: RuleSetRule['test'];
189
+ }): {parentRules: RuleSetRule[]; rule: RuleSetRule} | undefined {
190
+ for (const rule of rules) {
191
+ if (String(rule.test) === String(test)) {
192
+ return {parentRules: rules, rule};
193
+ }
194
+ if (rule.oneOf) {
195
+ const result = findAssetRule({
196
+ rules: rule.oneOf as RuleSetRule[],
197
+ test,
198
+ });
199
+ if (result) {
200
+ return result;
201
+ }
202
+ }
203
+ }
204
+ return undefined;
172
205
  }