Skip to content

Commit dc5ec32

Browse files
stnorJosh-Cena
andauthored
feat: make Webpack url-loader limit configurable (env variable) (#5498)
* Make urlLoaderLimit in the webpack config user-overridable via environment variable 'URL_LOADER_LIMIT'. * Apply suggestions from code review Co-authored-by: Joshua Chen <sidachen2003@gmail.com> * Changes as per @slorber's suggestions: * moving it to packages/docusaurus/src/constants.ts * name it WEBPACK_ URL_LOADER_LIMIT * add comment to say it's temporary, link to this PR/issue Co-authored-by: stnor <stefan@selessia.com> Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
1 parent 57c7a30 commit dc5ec32

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/docusaurus/src/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpa
3232
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
3333
export const DEFAULT_PORT = 3000;
3434
export const DEFAULT_PLUGIN_ID = 'default';
35+
36+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5493
37+
export const WEBPACK_URL_LOADER_LIMIT =
38+
process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;

packages/docusaurus/src/webpack/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import {
3434
BABEL_CONFIG_FILE_NAME,
3535
OUTPUT_STATIC_ASSETS_DIR_NAME,
36+
WEBPACK_URL_LOADER_LIMIT,
3637
} from '../constants';
3738
import {memoize} from 'lodash';
3839

@@ -326,8 +327,8 @@ type FileLoaderUtils = {
326327

327328
// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
328329
export function getFileLoaderUtils(): FileLoaderUtils {
329-
// files/images < 10kb will be inlined as base64 strings directly in the html
330-
const urlLoaderLimit = 10000;
330+
// files/images < urlLoaderLimit will be inlined as base64 strings directly in the html
331+
const urlLoaderLimit = WEBPACK_URL_LOADER_LIMIT;
331332

332333
// defines the path/pattern of the assets handled by webpack
333334
const fileLoaderFileName = (folder: AssetFolder) =>

0 commit comments

Comments
 (0)