@docusaurus/plugin-svgr 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `@docusaurus/plugin-svgr`
2
+
3
+ [SVGR](https://react-svgr.com/) plugin for Docusaurus.
4
+
5
+ ## Usage
6
+
7
+ See [plugin-svgr documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-svgr).
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { LoadContext, Plugin } from '@docusaurus/types';
8
+ import type { PluginOptions, Options } from './options';
9
+ export type { SVGRConfig, SVGOConfig } from './types';
10
+ export default function pluginSVGR(context: LoadContext, options: PluginOptions): Plugin;
11
+ export { validateOptions } from './options';
12
+ export type { PluginOptions, Options };
package/lib/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateOptions = void 0;
10
+ exports.default = pluginSVGR;
11
+ const svgrLoader_1 = require("./svgrLoader");
12
+ function pluginSVGR(context, options) {
13
+ return {
14
+ name: 'docusaurus-plugin-svgr',
15
+ configureWebpack: (config, isServer) => {
16
+ return {
17
+ module: {
18
+ rules: [(0, svgrLoader_1.createLoader)({ isServer, svgrConfig: options.svgrConfig })],
19
+ },
20
+ };
21
+ },
22
+ };
23
+ }
24
+ var options_1 = require("./options");
25
+ Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
@@ -0,0 +1,10 @@
1
+ import type { OptionValidationContext } from '@docusaurus/types';
2
+ import type { Config as SVGRConfig } from '@svgr/core';
3
+ export type PluginOptions = {
4
+ svgrConfig: SVGRConfig;
5
+ };
6
+ export type Options = {
7
+ svgrConfig?: Partial<SVGRConfig>;
8
+ };
9
+ export declare const DEFAULT_OPTIONS: Partial<PluginOptions>;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options | undefined, PluginOptions>): PluginOptions;
package/lib/options.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_OPTIONS = void 0;
4
+ exports.validateOptions = validateOptions;
5
+ /**
6
+ * Copyright (c) Facebook, Inc. and its affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ const utils_validation_1 = require("@docusaurus/utils-validation");
12
+ exports.DEFAULT_OPTIONS = {
13
+ svgrConfig: {},
14
+ };
15
+ const pluginOptionsSchema = utils_validation_1.Joi.object({
16
+ svgrConfig: utils_validation_1.Joi.object()
17
+ .pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.any())
18
+ .optional()
19
+ .default(exports.DEFAULT_OPTIONS.svgrConfig),
20
+ }).default(exports.DEFAULT_OPTIONS);
21
+ function validateOptions({ validate, options, }) {
22
+ return validate(pluginOptionsSchema, options);
23
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { SVGRConfig } from './types';
8
+ import type { RuleSetRule } from 'webpack';
9
+ type Params = {
10
+ isServer: boolean;
11
+ svgrConfig: SVGRConfig;
12
+ };
13
+ export declare function createLoader(params: Params): RuleSetRule;
14
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createLoader = createLoader;
10
+ const utils_1 = require("@docusaurus/utils");
11
+ // TODO Docusaurus v4: change these defaults?
12
+ // see https://github.com/facebook/docusaurus/issues/8297
13
+ // see https://github.com/facebook/docusaurus/pull/10205
14
+ // see https://github.com/facebook/docusaurus/pull/10211
15
+ const DefaultSVGOConfig = {
16
+ plugins: [
17
+ {
18
+ name: 'preset-default',
19
+ params: {
20
+ overrides: {
21
+ removeTitle: false,
22
+ removeViewBox: false,
23
+ },
24
+ },
25
+ },
26
+ ],
27
+ };
28
+ const DefaultSVGRConfig = {
29
+ prettier: false,
30
+ svgo: true,
31
+ svgoConfig: DefaultSVGOConfig,
32
+ titleProp: true,
33
+ };
34
+ function createSVGRLoader(params) {
35
+ const options = {
36
+ ...DefaultSVGRConfig,
37
+ ...params.svgrConfig,
38
+ };
39
+ return {
40
+ loader: require.resolve('@svgr/webpack'),
41
+ options,
42
+ };
43
+ }
44
+ function createLoader(params) {
45
+ const utils = (0, utils_1.getFileLoaderUtils)(params.isServer);
46
+ return {
47
+ test: /\.svg$/i,
48
+ oneOf: [
49
+ {
50
+ use: [createSVGRLoader(params)],
51
+ // We don't want to use SVGR loader for non-React source code
52
+ // ie we don't want to use SVGR for CSS files...
53
+ issuer: {
54
+ and: [/\.(?:tsx?|jsx?|mdx?)$/i],
55
+ },
56
+ },
57
+ {
58
+ use: [utils.loaders.url({ folder: 'images' })],
59
+ },
60
+ ],
61
+ };
62
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@docusaurus/plugin-svgr",
3
+ "version": "3.6.1",
4
+ "description": "SVGR plugin for Docusaurus.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc --build",
9
+ "watch": "tsc --build --watch"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/facebook/docusaurus.git",
17
+ "directory": "packages/docusaurus-plugin-svgr"
18
+ },
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@docusaurus/core": "3.6.1",
22
+ "@docusaurus/types": "3.6.1",
23
+ "@docusaurus/utils": "3.6.1",
24
+ "@docusaurus/utils-validation": "3.6.1",
25
+ "@svgr/core": "8.1.0",
26
+ "@svgr/webpack": "^8.1.0",
27
+ "tslib": "^2.6.0",
28
+ "webpack": "^5.88.1"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^18.0.0",
32
+ "react-dom": "^18.0.0"
33
+ },
34
+ "engines": {
35
+ "node": ">=18.0"
36
+ }
37
+ }
package/src/index.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {createLoader} from './svgrLoader';
9
+ import type {LoadContext, Plugin} from '@docusaurus/types';
10
+ import type {PluginOptions, Options} from './options';
11
+
12
+ export type {SVGRConfig, SVGOConfig} from './types';
13
+
14
+ export default function pluginSVGR(
15
+ context: LoadContext,
16
+ options: PluginOptions,
17
+ ): Plugin {
18
+ return {
19
+ name: 'docusaurus-plugin-svgr',
20
+ configureWebpack: (config, isServer) => {
21
+ return {
22
+ module: {
23
+ rules: [createLoader({isServer, svgrConfig: options.svgrConfig})],
24
+ },
25
+ };
26
+ },
27
+ };
28
+ }
29
+
30
+ export {validateOptions} from './options';
31
+
32
+ export type {PluginOptions, Options};
package/src/options.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import {Joi} from '@docusaurus/utils-validation';
8
+ import type {OptionValidationContext} from '@docusaurus/types';
9
+ import type {Config as SVGRConfig} from '@svgr/core';
10
+
11
+ export type PluginOptions = {
12
+ svgrConfig: SVGRConfig;
13
+ };
14
+
15
+ export type Options = {
16
+ svgrConfig?: Partial<SVGRConfig>;
17
+ };
18
+
19
+ export const DEFAULT_OPTIONS: Partial<PluginOptions> = {
20
+ svgrConfig: {},
21
+ };
22
+
23
+ const pluginOptionsSchema = Joi.object<PluginOptions>({
24
+ svgrConfig: Joi.object()
25
+ .pattern(Joi.string(), Joi.any())
26
+ .optional()
27
+ .default(DEFAULT_OPTIONS.svgrConfig),
28
+ }).default(DEFAULT_OPTIONS);
29
+
30
+ export function validateOptions({
31
+ validate,
32
+ options,
33
+ }: OptionValidationContext<Options | undefined, PluginOptions>): PluginOptions {
34
+ return validate(pluginOptionsSchema, options);
35
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {getFileLoaderUtils} from '@docusaurus/utils';
9
+
10
+ import type {SVGRConfig, SVGOConfig} from './types';
11
+ import type {RuleSetRule} from 'webpack';
12
+
13
+ // TODO Docusaurus v4: change these defaults?
14
+ // see https://github.com/facebook/docusaurus/issues/8297
15
+ // see https://github.com/facebook/docusaurus/pull/10205
16
+ // see https://github.com/facebook/docusaurus/pull/10211
17
+ const DefaultSVGOConfig: SVGOConfig = {
18
+ plugins: [
19
+ {
20
+ name: 'preset-default',
21
+ params: {
22
+ overrides: {
23
+ removeTitle: false,
24
+ removeViewBox: false,
25
+ },
26
+ },
27
+ },
28
+ ],
29
+ };
30
+
31
+ const DefaultSVGRConfig: SVGRConfig = {
32
+ prettier: false,
33
+ svgo: true,
34
+ svgoConfig: DefaultSVGOConfig,
35
+ titleProp: true,
36
+ };
37
+
38
+ type Params = {isServer: boolean; svgrConfig: SVGRConfig};
39
+
40
+ function createSVGRLoader(params: Params): RuleSetRule {
41
+ const options: SVGRConfig = {
42
+ ...DefaultSVGRConfig,
43
+ ...params.svgrConfig,
44
+ };
45
+ return {
46
+ loader: require.resolve('@svgr/webpack'),
47
+ options,
48
+ };
49
+ }
50
+
51
+ export function createLoader(params: Params): RuleSetRule {
52
+ const utils = getFileLoaderUtils(params.isServer);
53
+ return {
54
+ test: /\.svg$/i,
55
+ oneOf: [
56
+ {
57
+ use: [createSVGRLoader(params)],
58
+ // We don't want to use SVGR loader for non-React source code
59
+ // ie we don't want to use SVGR for CSS files...
60
+ issuer: {
61
+ and: [/\.(?:tsx?|jsx?|mdx?)$/i],
62
+ },
63
+ },
64
+ {
65
+ use: [utils.loaders.url({folder: 'images'})],
66
+ },
67
+ ],
68
+ };
69
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /// <reference types="@docusaurus/module-type-aliases" />
9
+
10
+ export type {Config as SVGRConfig} from '@svgr/core';
11
+
12
+ export type SVGOConfig = NonNullable<SVGRConfig['svgoConfig']>;