diff options
Diffstat (limited to 'subprojects/docs/src/plugins/loadersPlugin.ts')
-rw-r--r-- | subprojects/docs/src/plugins/loadersPlugin.ts | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/subprojects/docs/src/plugins/loadersPlugin.ts b/subprojects/docs/src/plugins/loadersPlugin.ts index 325d7f67..8b52667c 100644 --- a/subprojects/docs/src/plugins/loadersPlugin.ts +++ b/subprojects/docs/src/plugins/loadersPlugin.ts | |||
@@ -1,15 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2024 The Refinery Authors | 2 | * Copyright (c) 2016, Jeremy Stucki |
3 | * Copyright (c) Facebook, Inc. and its affiliates. | ||
4 | * Copyright (c) 2024 The Refinery Authors | ||
3 | * | 5 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 6 | * SPDX-License-Identifier: BSD-3-Clause AND MIT AND EPL-2.0 |
5 | */ | 7 | */ |
6 | 8 | ||
7 | import type { Plugin } from '@docusaurus/types'; | 9 | import type { Plugin } from '@docusaurus/types'; |
10 | // @ts-expect-error No typings available for `responsive-loader`. | ||
11 | import sharp from 'responsive-loader/sharp'; | ||
8 | 12 | ||
9 | export default function loadersPlugin(): Plugin { | 13 | export default function loadersPlugin(): Plugin { |
10 | return { | 14 | return { |
11 | name: 'refinery-loaders-plugin', | 15 | name: 'refinery-loaders-plugin', |
12 | configureWebpack(config) { | 16 | configureWebpack(config, isServer) { |
13 | let svgoDisabled = false; | 17 | let svgoDisabled = false; |
14 | const rules = [...(config.module?.rules ?? [])]; | 18 | const rules = [...(config.module?.rules ?? [])]; |
15 | rules.forEach((rule) => { | 19 | rules.forEach((rule) => { |
@@ -38,6 +42,8 @@ export default function loadersPlugin(): Plugin { | |||
38 | ) { | 42 | ) { |
39 | return; | 43 | return; |
40 | } | 44 | } |
45 | // Skip SVGR when importing SVG files with ?url. | ||
46 | svgLoader.resourceQuery = { not: /[?&]url$/ }; | ||
41 | const { | 47 | const { |
42 | use: [loader], | 48 | use: [loader], |
43 | } = svgLoader; | 49 | } = svgLoader; |
@@ -48,6 +54,7 @@ export default function loadersPlugin(): Plugin { | |||
48 | ) { | 54 | ) { |
49 | return; | 55 | return; |
50 | } | 56 | } |
57 | |||
51 | loader.options = { | 58 | loader.options = { |
52 | ...(typeof loader.options === 'object' ? loader.options : {}), | 59 | ...(typeof loader.options === 'object' ? loader.options : {}), |
53 | svgo: true, | 60 | svgo: true, |
@@ -78,7 +85,31 @@ export default function loadersPlugin(): Plugin { | |||
78 | 'module.rules': 'replace', | 85 | 'module.rules': 'replace', |
79 | }, | 86 | }, |
80 | module: { | 87 | module: { |
81 | rules, | 88 | rules: [ |
89 | // Configuration based on | ||
90 | // https://github.com/dazuaz/responsive-loader/blob/ef2c806fcd36f06f6be8a0b97e09f40c3d86d3ac/README.md | ||
91 | { | ||
92 | test: /\.(png|jpe?g)$/, | ||
93 | resourceQuery: /[?&]rl$/, | ||
94 | use: [ | ||
95 | { | ||
96 | loader: 'responsive-loader', | ||
97 | options: { | ||
98 | /* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- | ||
99 | * No typings available for `responsive-loader`. | ||
100 | */ | ||
101 | adapter: sharp, | ||
102 | format: 'webp', | ||
103 | // See | ||
104 | // https://github.com/facebook/docusaurus/blob/c745021b01a8b88d34e1d772278d7171ad8acdf5/packages/docusaurus-plugin-ideal-image/src/index.ts#L62-L66 | ||
105 | emitFile: !isServer, | ||
106 | name: 'assets/images/[name].[hash:hex:7].[width].[ext]', | ||
107 | }, | ||
108 | }, | ||
109 | ], | ||
110 | }, | ||
111 | ...rules, | ||
112 | ], | ||
82 | }, | 113 | }, |
83 | }; | 114 | }; |
84 | }, | 115 | }, |