Skip to content

Commit

Permalink
Keep existing image folder for md image assets
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 5, 2023
1 parent 9a1d41c commit a952f4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/docusaurus-mdx-loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {LoaderContext} from 'webpack';
type Pluggable = any; // TODO fix this asap

const {
loaders: {inlineMarkdownAssetFileLoader},
loaders: {inlineMarkdownAssetImageFileLoader},
} = getFileLoaderUtils();

export type MDXPlugin = Pluggable;
Expand Down Expand Up @@ -92,8 +92,9 @@ function createAssetsExportCode(assets: unknown) {
if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
// TODO do we have other use-cases than image assets?
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
const inlineLoader = inlineMarkdownAssetFileLoader;
return `require("${inlineLoader}${escapePath(assetValue)}").default`;
return `require("${inlineMarkdownAssetImageFileLoader}${escapePath(
assetValue,
)}").default`;
}
return undefined;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-utils/src/webpackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
} from './constants';
import type {RuleSetRule} from 'webpack';

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

type FileLoaderUtils = {
loaders: {
file: (options: {folder: AssetFolder}) => RuleSetRule;
url: (options: {folder: AssetFolder}) => RuleSetRule;
inlineMarkdownImageFileLoader: string;
inlineMarkdownAssetFileLoader: string;
inlineMarkdownAssetImageFileLoader: string;
inlineMarkdownLinkFileLoader: string;
};
rules: {
Expand Down Expand Up @@ -75,9 +75,9 @@ export function getFileLoaderUtils(): FileLoaderUtils {
)}?limit=${urlLoaderLimit}&name=${fileLoaderFileName(
'images',
)}&fallback=${escapePath(require.resolve('file-loader'))}!`,
inlineMarkdownAssetFileLoader: `!${escapePath(
inlineMarkdownAssetImageFileLoader: `!${escapePath(
require.resolve('file-loader'),
)}?name=${fileLoaderFileName('assets')}!`,
)}?name=${fileLoaderFileName('images')}!`,
inlineMarkdownLinkFileLoader: `!${escapePath(
require.resolve('file-loader'),
)}?name=${fileLoaderFileName('files')}!`,
Expand Down

0 comments on commit a952f4c

Please sign in to comment.