mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-25 20:48:50 +02:00
refactor(v2): convert @docusaurus/plugin-ideal-image
to TypeScript (#2011)
* refactor @docusaurus/plugin-ideal-image refactor @docusaurus/plugin-ideal-image * Update react-ideal-image.d.ts * Update types.ts * Update IdealImage.tsx * Update package.json
This commit is contained in:
parent
39e9e755c3
commit
104733914a
9 changed files with 102 additions and 8 deletions
50
packages/docusaurus-plugin-ideal-image/src/index.ts
Normal file
50
packages/docusaurus-plugin-ideal-image/src/index.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
import {PluginOptions} from './types';
|
||||
import {Configuration} from 'webpack';
|
||||
|
||||
import path from 'path';
|
||||
|
||||
export = function(_context: LoadContext, options: PluginOptions) {
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
return {
|
||||
name: 'docusaurus-plugin-ideal-image',
|
||||
|
||||
getThemePath() {
|
||||
return path.resolve(__dirname, './theme');
|
||||
},
|
||||
|
||||
configureWebpack(_config: Configuration, isServer: boolean) {
|
||||
return {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(png|jpe?g|gif)$/i,
|
||||
use: [
|
||||
'@endiliey/lqip-loader',
|
||||
{
|
||||
loader: '@endiliey/responsive-loader',
|
||||
options: {
|
||||
emitFile: !isServer, // don't emit for server-side rendering
|
||||
disable: !isProd,
|
||||
// eslint-disable-next-line
|
||||
adapter: require('@endiliey/responsive-loader/sharp'),
|
||||
name: isProd
|
||||
? 'ideal-img/[name].[hash:hex:7].[width].[ext]'
|
||||
: 'ideal-img/[name].[width].[ext]',
|
||||
...options,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue