/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-plugin-ideal-image/src/index.ts
93 строки
3 KB
Sébastien Lorber
chore(monorepo): upgrade monorepo to ESLint 9 (#12024)
15 май 2026, 21:08
Не верифицирован
15 май 2026, 21:08
7518645
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import {Joi} from '@docusaurus/utils-validation'; import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations'; import type { LoadContext, Plugin, OptionValidationContext, } from '@docusaurus/types'; import type {PluginOptions} from '@docusaurus/plugin-ideal-image'; export default function pluginIdealImage( context: LoadContext, options: PluginOptions, ): Plugin<void> { const { i18n: {currentLocale}, } = context; return { name: 'docusaurus-plugin-ideal-image', getThemePath() { return '../lib/theme'; }, getTypeScriptThemePath() { return '../src/theme'; }, getDefaultCodeTranslationMessages() { return readDefaultCodeTranslationMessages({ locale: currentLocale, name: 'plugin-ideal-image', }); }, configureWebpack(_config, isServer) { const {disableInDev, ...loaderOptions} = options; if (disableInDev && process.env.NODE_ENV !== 'production') { return {}; } return { mergeStrategy: { 'module.rules': 'prepend', }, module: { rules: [ { test: /\.(?:png|jpe?g)$/i, // We don't want to use the image loader for non-React source code // ie we don't want to use ideal image loader for CSS files... // See https://github.com/facebook/docusaurus/issues/10862 issuer: { and: [/\.(?:tsx?|jsx?|mdx?)$/i], }, use: [ require.resolve('@docusaurus/lqip-loader'), { loader: require.resolve('@docusaurus/responsive-loader'), options: { // Don't emit for server-side rendering emitFile: !isServer, // eslint-disable-next-line @typescript-eslint/no-require-imports adapter: require('@docusaurus/responsive-loader/sharp'), name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]', ...loaderOptions, }, }, ], }, ], }, }; }, }; } export function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions { const pluginOptionsSchema = Joi.object<PluginOptions>({ disableInDev: Joi.boolean().default(true), }).unknown(); return validate(pluginOptionsSchema, options); }