Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getCustomBabelConfigFilePath,
getMinimizer,
} from './utils';
import {STATIC_ASSETS_DIR_NAME} from '../constants';

const CSS_REGEX = /\.css$/;
const CSS_MODULE_REGEX = /\.module\.css$/;
Expand Down Expand Up @@ -91,6 +92,14 @@ export function createBaseConfig(
resolve: {
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
symlinks: true,
roots: [
// Allow resolution of url("/fonts/xyz.ttf") by webpack
// See https://webpack.js.org/configuration/resolve/#resolveroots
// See https://github.com/webpack-contrib/css-loader/issues/1256
path.join(siteDir, STATIC_ASSETS_DIR_NAME),
siteDir,
process.cwd(),
],
alias: {
'@site': siteDir,
'@generated': generatedFilesDir,
Expand Down Expand Up @@ -152,6 +161,7 @@ export function createBaseConfig(
module: {
rules: [
fileLoaderUtils.rules.images(),
fileLoaderUtils.rules.fonts(),
fileLoaderUtils.rules.media(),
fileLoaderUtils.rules.svg(),
fileLoaderUtils.rules.otherAssets(),
Expand Down
9 changes: 8 additions & 1 deletion packages/docusaurus/src/webpack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function compile(config: Configuration[]): Promise<Stats.ToJsonOutput> {
});
}

type AssetFolder = 'images' | 'files' | 'medias';
type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';

// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
export function getFileLoaderUtils(): Record<string, any> {
Expand Down Expand Up @@ -291,6 +291,13 @@ export function getFileLoaderUtils(): Record<string, any> {
};
},

fonts: (): RuleSetRule => {
return {
use: [loaders.url({folder: 'fonts'})],
test: /\.(woff|woff2|eot|ttf|otf)$/,
};
},

/**
* Loads audio and video and inlines them via a data URI if they are below
* the size threshold
Expand Down