mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 11:36:53 +02:00
fix(ideal-image): fix IdealImage in dev not handling ES import images properly (#5760)
This commit is contained in:
parent
1c8b8362f7
commit
31ad8c4def
3 changed files with 38 additions and 2 deletions
|
@ -12,8 +12,15 @@ function Image(props) {
|
|||
const {alt, className, img} = props;
|
||||
|
||||
// In dev env just use regular img with original file
|
||||
if (img.default) {
|
||||
return <img src={img.default} className={className} alt={alt} {...props} />;
|
||||
if (typeof img === 'string' || typeof img.default === 'string') {
|
||||
return (
|
||||
<img
|
||||
src={img?.default ?? img}
|
||||
className={className}
|
||||
alt={alt}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
19
website/_dogfooding/_docs tests/tests/img-tests.mdx
Normal file
19
website/_dogfooding/_docs tests/tests/img-tests.mdx
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Image tests
|
||||
|
||||
import Image from '@theme/IdealImage';
|
||||
|
||||
import docusaurusImport from '@site/static/img/docusaurus.png';
|
||||
|
||||
export const docusaurusRequire = require('@site/static/img/docusaurus.png');
|
||||
|
||||
## Regular images
|
||||
|
||||
<img src={docusaurusImport} />
|
||||
|
||||
<img src={docusaurusRequire.default} />
|
||||
|
||||
## Ideal images
|
||||
|
||||
<Image img={docusaurusImport} />
|
||||
|
||||
<Image img={docusaurusRequire} />
|
|
@ -13,6 +13,16 @@ module.exports = {
|
|||
className: 'red',
|
||||
label: 'Index',
|
||||
},
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Tests',
|
||||
items: [
|
||||
{
|
||||
type: 'autogenerated',
|
||||
dirName: 'tests',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'category',
|
||||
label: 'section',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue