mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 11:22:30 +02:00
feat(ideal-image): new option disableInDev (#6155)
* feat(ideal-image): new option disableInDev * Add docs * Use import type * More docs
This commit is contained in:
parent
8cd593379c
commit
e1bff072fe
5 changed files with 73 additions and 26 deletions
|
@ -23,6 +23,7 @@
|
|||
"dependencies": {
|
||||
"@docusaurus/core": "2.0.0-beta.14",
|
||||
"@docusaurus/lqip-loader": "2.0.0-beta.14",
|
||||
"@docusaurus/utils-validation": "2.0.0-beta.14",
|
||||
"@docusaurus/responsive-loader": "1.5.0",
|
||||
"@endiliey/react-ideal-image": "^0.0.11",
|
||||
"react-waypoint": "^10.1.0",
|
||||
|
|
|
@ -5,13 +5,19 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {LoadContext, Plugin} from '@docusaurus/types';
|
||||
import type {
|
||||
LoadContext,
|
||||
Plugin,
|
||||
OptionValidationContext,
|
||||
ValidationResult,
|
||||
} from '@docusaurus/types';
|
||||
import type {PluginOptions} from '@docusaurus/plugin-ideal-image';
|
||||
import {Configuration} from 'webpack';
|
||||
import type {Configuration} from 'webpack';
|
||||
import {Joi} from '@docusaurus/utils-validation';
|
||||
|
||||
import path from 'path';
|
||||
|
||||
export default function (
|
||||
export default function pluginIdealImage(
|
||||
_context: LoadContext,
|
||||
options: PluginOptions,
|
||||
): Plugin<void> {
|
||||
|
@ -19,11 +25,16 @@ export default function (
|
|||
name: 'docusaurus-plugin-ideal-image',
|
||||
|
||||
getThemePath() {
|
||||
return path.resolve(__dirname, './theme');
|
||||
return path.resolve(__dirname, '../lib/theme');
|
||||
},
|
||||
|
||||
getTypeScriptThemePath() {
|
||||
return path.resolve(__dirname, '../src/theme');
|
||||
},
|
||||
|
||||
configureWebpack(_config: Configuration, isServer: boolean) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const {disableInDev, ...loaderOptions} = options;
|
||||
if (disableInDev && process.env.NODE_ENV !== 'production') {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -44,7 +55,7 @@ export default function (
|
|||
// eslint-disable-next-line global-require
|
||||
adapter: require('@docusaurus/responsive-loader/sharp'),
|
||||
name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]',
|
||||
...options,
|
||||
...loaderOptions,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -55,3 +66,13 @@ export default function (
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function validateOptions({
|
||||
validate,
|
||||
options,
|
||||
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
|
||||
const pluginOptionsSchema = Joi.object({
|
||||
disableInDev: Joi.boolean().default(true),
|
||||
}).unknown();
|
||||
return validate(pluginOptionsSchema, options);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ declare module '@docusaurus/plugin-ideal-image' {
|
|||
* JPEG compression quality
|
||||
*/
|
||||
quality?: number;
|
||||
/**
|
||||
* Just use regular images in dev mode
|
||||
*/
|
||||
disableInDev?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue