react-icons-sprite 0.1.0 → 0.2.0
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/dist/vite/plugin.d.ts +6 -0
- package/dist/vite/plugin.js +8 -6
- package/package.json +1 -1
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ type ReactIconsSpriteVitePluginOptions = {
|
|
|
7
7
|
* Example: { spriteUrlVersion: "1.2.3" } -> "/assets/react-icons-sprite.svg?v=1.2.3"
|
|
8
8
|
*/
|
|
9
9
|
spriteUrlVersion?: string;
|
|
10
|
+
/**
|
|
11
|
+
* If passed, this exact string will be used for the emitted file name.
|
|
12
|
+
* If fileName is omitted, name will be generated as `react-icons-sprite-[hash].svg.
|
|
13
|
+
* This is useful when, for example, multiple sprite sheets are generated during client and server builds.
|
|
14
|
+
*/
|
|
15
|
+
fileName?: string;
|
|
10
16
|
};
|
|
11
17
|
declare const reactIconsSprite: (options?: ReactIconsSpriteVitePluginOptions) => Plugin;
|
|
12
18
|
//#endregion
|
package/dist/vite/plugin.js
CHANGED
|
@@ -196,7 +196,7 @@ const createCollector = () => {
|
|
|
196
196
|
//#endregion
|
|
197
197
|
//#region src/vite/plugin.ts
|
|
198
198
|
const reactIconsSprite = (options = {}) => {
|
|
199
|
-
const { spriteUrlVersion } = options;
|
|
199
|
+
const { spriteUrlVersion, fileName } = options;
|
|
200
200
|
const collector = createCollector();
|
|
201
201
|
return {
|
|
202
202
|
name: "vite-plugin-react-icons-sprite",
|
|
@@ -225,13 +225,15 @@ const reactIconsSprite = (options = {}) => {
|
|
|
225
225
|
},
|
|
226
226
|
async generateBundle(_options, bundle) {
|
|
227
227
|
const spriteXml = await buildSprite(collector.toList());
|
|
228
|
-
const
|
|
228
|
+
const emitFileOptions = {
|
|
229
229
|
type: "asset",
|
|
230
|
-
name: "react-icons-sprite.svg",
|
|
231
230
|
source: spriteXml
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
};
|
|
232
|
+
if (fileName) emitFileOptions.fileName = fileName;
|
|
233
|
+
else emitFileOptions.name = "react-icons-sprite.svg";
|
|
234
|
+
const assetId = this.emitFile(emitFileOptions);
|
|
235
|
+
const name = this.getFileName(assetId);
|
|
236
|
+
const finalUrl = spriteUrlVersion && spriteUrlVersion.length > 0 ? `/${name}?v=${encodeURIComponent(spriteUrlVersion)}` : `/${name}`;
|
|
235
237
|
for (const [, item] of Object.entries(bundle)) if (item.type === "chunk" && typeof item.code === "string") {
|
|
236
238
|
if (item.code.includes(PLACEHOLDER)) item.code = item.code.replaceAll(PLACEHOLDER, finalUrl);
|
|
237
239
|
}
|