@rsbuild/plugin-svgr 0.6.15 → 0.7.0-beta.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.
@@ -1,24 +1,41 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
-
5
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.49.3_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
6
- import { fileURLToPath } from "url";
7
- import path from "path";
8
- var getFilename = () => fileURLToPath(import.meta.url);
9
- var getDirname = () => path.dirname(getFilename());
10
- var __dirname = /* @__PURE__ */ getDirname();
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
11
29
 
12
30
  // src/index.ts
13
- import path2 from "path";
14
- import { PLUGIN_REACT_NAME } from "@rsbuild/plugin-react";
15
- import {
16
- SCRIPT_REGEX,
17
- SVG_REGEX,
18
- deepmerge,
19
- getDistPath,
20
- getFilename as getFilename2
21
- } from "@rsbuild/shared";
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ pluginSvgr: () => pluginSvgr
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_node_path = __toESM(require("path"));
37
+ var import_plugin_react = require("@rsbuild/plugin-react");
38
+ var import_shared = require("@rsbuild/shared");
22
39
  function getSvgoDefaultConfig() {
23
40
  return {
24
41
  plugins: [
@@ -38,13 +55,13 @@ function getSvgoDefaultConfig() {
38
55
  }
39
56
  var pluginSvgr = (options = {}) => ({
40
57
  name: "rsbuild:svgr",
41
- pre: [PLUGIN_REACT_NAME],
58
+ pre: [import_plugin_react.PLUGIN_REACT_NAME],
42
59
  setup(api) {
43
60
  api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
44
61
  const config = api.getNormalizedConfig();
45
- const distDir = getDistPath(config, "svg");
46
- const filename = getFilename2(config, "svg", isProd);
47
- const outputName = path2.posix.join(distDir, filename);
62
+ const distDir = (0, import_shared.getDistPath)(config, "svg");
63
+ const filename = (0, import_shared.getFilename)(config, "svg", isProd);
64
+ const outputName = import_node_path.default.posix.join(distDir, filename);
48
65
  const { dataUriLimit } = config.output;
49
66
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit.svg;
50
67
  let generatorOptions = {};
@@ -52,8 +69,8 @@ var pluginSvgr = (options = {}) => ({
52
69
  generatorOptions = chain.module.rules.get(CHAIN_ID.RULE.SVG).oneOfs.get(CHAIN_ID.ONE_OF.SVG_URL).get("generator");
53
70
  chain.module.rules.delete(CHAIN_ID.RULE.SVG);
54
71
  }
55
- const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX);
56
- const svgrOptions = deepmerge(
72
+ const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(import_shared.SVG_REGEX);
73
+ const svgrOptions = (0, import_shared.deepmerge)(
57
74
  {
58
75
  svgo: true,
59
76
  svgoConfig: getSvgoDefaultConfig()
@@ -62,25 +79,25 @@ var pluginSvgr = (options = {}) => ({
62
79
  );
63
80
  rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", generatorOptions);
64
81
  rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type("asset/inline").resourceQuery(/inline/);
65
- rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader")).options({
82
+ rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader.cjs")).options({
66
83
  ...svgrOptions,
67
84
  exportType: "default"
68
85
  }).end();
69
86
  const { mixedImport = false } = options;
70
87
  if (mixedImport || svgrOptions.exportType) {
71
88
  const { exportType = mixedImport ? "named" : void 0 } = svgrOptions;
72
- const issuerInclude = [SCRIPT_REGEX, /\.mdx$/];
89
+ const issuerInclude = [import_shared.SCRIPT_REGEX, /\.mdx$/];
73
90
  const issuer = options.excludeImporter ? { and: [issuerInclude, { not: options.excludeImporter }] } : issuerInclude;
74
91
  const svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG);
75
92
  if (options.exclude) {
76
93
  svgRule.exclude.add(options.exclude);
77
94
  }
78
- svgRule.type("javascript/auto").set("issuer", issuer).use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader")).options({
95
+ svgRule.type("javascript/auto").set("issuer", issuer).use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader.cjs")).options({
79
96
  ...svgrOptions,
80
97
  exportType
81
98
  }).end();
82
99
  if (mixedImport && exportType === "named") {
83
- svgRule.use(CHAIN_ID.USE.URL).loader(path2.join(__dirname, "../compiled", "url-loader")).options({
100
+ svgRule.use(CHAIN_ID.USE.URL).loader(import_node_path.default.join(__dirname, "../compiled", "url-loader/index.js")).options({
84
101
  limit: maxSize,
85
102
  name: outputName
86
103
  });
@@ -112,6 +129,7 @@ var pluginSvgr = (options = {}) => ({
112
129
  });
113
130
  }
114
131
  });
115
- export {
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
116
134
  pluginSvgr
117
- };
135
+ });
package/dist/index.js CHANGED
@@ -1,41 +1,24 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import { createRequire } from 'module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+
5
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.49.3_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
6
+ import { fileURLToPath } from "url";
7
+ import path from "path";
8
+ var getFilename = () => fileURLToPath(import.meta.url);
9
+ var getDirname = () => path.dirname(getFilename());
10
+ var __dirname = /* @__PURE__ */ getDirname();
29
11
 
30
12
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- pluginSvgr: () => pluginSvgr
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
- var import_node_path = __toESM(require("path"));
37
- var import_plugin_react = require("@rsbuild/plugin-react");
38
- var import_shared = require("@rsbuild/shared");
13
+ import path2 from "path";
14
+ import { PLUGIN_REACT_NAME } from "@rsbuild/plugin-react";
15
+ import {
16
+ SCRIPT_REGEX,
17
+ SVG_REGEX,
18
+ deepmerge,
19
+ getDistPath,
20
+ getFilename as getFilename2
21
+ } from "@rsbuild/shared";
39
22
  function getSvgoDefaultConfig() {
40
23
  return {
41
24
  plugins: [
@@ -55,13 +38,13 @@ function getSvgoDefaultConfig() {
55
38
  }
56
39
  var pluginSvgr = (options = {}) => ({
57
40
  name: "rsbuild:svgr",
58
- pre: [import_plugin_react.PLUGIN_REACT_NAME],
41
+ pre: [PLUGIN_REACT_NAME],
59
42
  setup(api) {
60
43
  api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
61
44
  const config = api.getNormalizedConfig();
62
- const distDir = (0, import_shared.getDistPath)(config, "svg");
63
- const filename = (0, import_shared.getFilename)(config, "svg", isProd);
64
- const outputName = import_node_path.default.posix.join(distDir, filename);
45
+ const distDir = getDistPath(config, "svg");
46
+ const filename = getFilename2(config, "svg", isProd);
47
+ const outputName = path2.posix.join(distDir, filename);
65
48
  const { dataUriLimit } = config.output;
66
49
  const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit.svg;
67
50
  let generatorOptions = {};
@@ -69,8 +52,8 @@ var pluginSvgr = (options = {}) => ({
69
52
  generatorOptions = chain.module.rules.get(CHAIN_ID.RULE.SVG).oneOfs.get(CHAIN_ID.ONE_OF.SVG_URL).get("generator");
70
53
  chain.module.rules.delete(CHAIN_ID.RULE.SVG);
71
54
  }
72
- const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(import_shared.SVG_REGEX);
73
- const svgrOptions = (0, import_shared.deepmerge)(
55
+ const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX);
56
+ const svgrOptions = deepmerge(
74
57
  {
75
58
  svgo: true,
76
59
  svgoConfig: getSvgoDefaultConfig()
@@ -79,25 +62,25 @@ var pluginSvgr = (options = {}) => ({
79
62
  );
80
63
  rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", generatorOptions);
81
64
  rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type("asset/inline").resourceQuery(/inline/);
82
- rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader")).options({
65
+ rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader.cjs")).options({
83
66
  ...svgrOptions,
84
67
  exportType: "default"
85
68
  }).end();
86
69
  const { mixedImport = false } = options;
87
70
  if (mixedImport || svgrOptions.exportType) {
88
71
  const { exportType = mixedImport ? "named" : void 0 } = svgrOptions;
89
- const issuerInclude = [import_shared.SCRIPT_REGEX, /\.mdx$/];
72
+ const issuerInclude = [SCRIPT_REGEX, /\.mdx$/];
90
73
  const issuer = options.excludeImporter ? { and: [issuerInclude, { not: options.excludeImporter }] } : issuerInclude;
91
74
  const svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG);
92
75
  if (options.exclude) {
93
76
  svgRule.exclude.add(options.exclude);
94
77
  }
95
- svgRule.type("javascript/auto").set("issuer", issuer).use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader")).options({
78
+ svgRule.type("javascript/auto").set("issuer", issuer).use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader.cjs")).options({
96
79
  ...svgrOptions,
97
80
  exportType
98
81
  }).end();
99
82
  if (mixedImport && exportType === "named") {
100
- svgRule.use(CHAIN_ID.USE.URL).loader(import_node_path.default.join(__dirname, "../compiled", "url-loader")).options({
83
+ svgRule.use(CHAIN_ID.USE.URL).loader(path2.join(__dirname, "../compiled", "url-loader/index.js")).options({
101
84
  limit: maxSize,
102
85
  name: outputName
103
86
  });
@@ -129,7 +112,6 @@ var pluginSvgr = (options = {}) => ({
129
112
  });
130
113
  }
131
114
  });
132
- // Annotate the CommonJS export names for ESM import in node:
133
- 0 && (module.exports = {
115
+ export {
134
116
  pluginSvgr
135
- });
117
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-svgr",
3
- "version": "0.6.15",
3
+ "version": "0.7.0-beta.1",
4
4
  "description": "svgr plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,15 +8,15 @@
8
8
  "directory": "packages/plugin-svgr"
9
9
  },
10
10
  "license": "MIT",
11
- "type": "commonjs",
11
+ "type": "module",
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
15
- "import": "./dist/index.mjs",
16
- "default": "./dist/index.js"
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
17
  }
18
18
  },
19
- "main": "./dist/index.js",
19
+ "main": "./dist/index.cjs",
20
20
  "types": "./dist/index.d.ts",
21
21
  "files": [
22
22
  "dist",
@@ -26,8 +26,8 @@
26
26
  "@svgr/core": "8.1.0",
27
27
  "@svgr/plugin-jsx": "8.1.0",
28
28
  "@svgr/plugin-svgo": "8.1.0",
29
- "@rsbuild/plugin-react": "0.6.15",
30
- "@rsbuild/shared": "0.6.15"
29
+ "@rsbuild/plugin-react": "0.7.0-beta.1",
30
+ "@rsbuild/shared": "0.7.0-beta.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "18.x",
@@ -35,11 +35,11 @@
35
35
  "prebundle": "1.1.0",
36
36
  "typescript": "^5.4.2",
37
37
  "url-loader": "4.1.1",
38
- "@rsbuild/core": "0.6.15",
39
- "@scripts/test-helper": "0.6.15"
38
+ "@rsbuild/core": "0.7.0-beta.1",
39
+ "@scripts/test-helper": "0.7.0-beta.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "@rsbuild/core": "^0.6.15"
42
+ "@rsbuild/core": "^0.7.0-beta.1"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public",
package/dist/loader.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Rspack } from '@rsbuild/core';
2
- import { Config } from '@svgr/core';
3
-
4
- /**
5
- * Copyright (c) 2017, Smooth Code
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- * modified from https://github.com/gregberge/svgr/blob/7595d378b73d4826a4cead165b3f32386b07315b/packages/webpack/src/index.ts
10
- */
11
-
12
- declare function svgrLoader(this: Rspack.LoaderContext<Config>, contents: string): void;
13
-
14
- export { svgrLoader as default };
File without changes