svger-cli 2.0.7 → 3.0.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.
@@ -0,0 +1,543 @@
1
+ # SVGER-CLI Build Tool Integrations
2
+
3
+ Official build tool integrations for SVGER-CLI, providing seamless SVG to component conversion in
4
+ your existing build pipeline.
5
+
6
+ ## 🚀 Quick Start
7
+
8
+ ```bash
9
+ npm install svger-cli --save-dev
10
+ ```
11
+
12
+ ## 📦 Available Integrations
13
+
14
+ - **[Webpack](#webpack-integration)** - Plugin & Loader with HMR
15
+ - **[Vite](#vite-integration)** - Plugin with HMR & Virtual Modules
16
+ - **[Rollup](#rollup-integration)** - Plugin with Tree-Shaking
17
+ - **[Babel](#babel-integration)** - Plugin with Import Transformation
18
+ - **[Next.js](#nextjs-integration)** - Wrapper with SSR Support
19
+ - **[Jest](#jest-integration)** - Preset & Transformer
20
+
21
+ ---
22
+
23
+ ## Webpack Integration
24
+
25
+ ### Installation
26
+
27
+ ```bash
28
+ npm install svger-cli --save-dev
29
+ ```
30
+
31
+ ### Usage
32
+
33
+ **webpack.config.js:**
34
+
35
+ ```javascript
36
+ const { SvgerWebpackPlugin } = require('svger-cli/webpack');
37
+
38
+ module.exports = {
39
+ plugins: [
40
+ new SvgerWebpackPlugin({
41
+ source: './src/icons',
42
+ output: './src/components/icons',
43
+ framework: 'react',
44
+ typescript: true,
45
+ hmr: true,
46
+ generateIndex: true,
47
+ }),
48
+ ],
49
+
50
+ module: {
51
+ rules: [
52
+ {
53
+ test: /\.svg$/,
54
+ use: [
55
+ {
56
+ loader: 'svger-cli/webpack-loader',
57
+ options: {
58
+ framework: 'react',
59
+ typescript: true,
60
+ },
61
+ },
62
+ ],
63
+ },
64
+ ],
65
+ },
66
+ };
67
+ ```
68
+
69
+ ### Options
70
+
71
+ | Option | Type | Default | Description |
72
+ | --------------- | ------- | -------------------------- | -------------------------------------------- |
73
+ | `source` | string | `'./src/icons'` | Source directory containing SVG files |
74
+ | `output` | string | `'./src/components/icons'` | Output directory for generated components |
75
+ | `framework` | string | `'react'` | Target framework (react, vue, angular, etc.) |
76
+ | `typescript` | boolean | `true` | Generate TypeScript files |
77
+ | `hmr` | boolean | `true` | Enable Hot Module Replacement |
78
+ | `generateIndex` | boolean | `true` | Generate index file with exports |
79
+
80
+ [See full example →](./examples/webpack.config.example.js)
81
+
82
+ ---
83
+
84
+ ## Vite Integration
85
+
86
+ ### Installation
87
+
88
+ ```bash
89
+ npm install svger-cli --save-dev
90
+ ```
91
+
92
+ ### Usage
93
+
94
+ **vite.config.js:**
95
+
96
+ ```javascript
97
+ import { svgerVitePlugin } from 'svger-cli/vite';
98
+
99
+ export default {
100
+ plugins: [
101
+ svgerVitePlugin({
102
+ source: './src/icons',
103
+ output: './src/components/icons',
104
+ framework: 'react',
105
+ typescript: true,
106
+ hmr: true,
107
+ }),
108
+ ],
109
+ };
110
+ ```
111
+
112
+ ### Options
113
+
114
+ | Option | Type | Default | Description |
115
+ | ------------ | ------- | -------------------------- | ----------------------------------------- |
116
+ | `source` | string | `'./src/icons'` | Source directory containing SVG files |
117
+ | `output` | string | `'./src/components/icons'` | Output directory for generated components |
118
+ | `framework` | string | `'react'` | Target framework |
119
+ | `typescript` | boolean | `true` | Generate TypeScript files |
120
+ | `hmr` | boolean | `true` | Enable Hot Module Replacement |
121
+ | `virtual` | boolean | `false` | Use virtual modules |
122
+ | `exportType` | string | `'default'` | Export type ('default' or 'named') |
123
+
124
+ [See full example →](./examples/vite.config.example.js)
125
+
126
+ ---
127
+
128
+ ## Rollup Integration
129
+
130
+ ### Installation
131
+
132
+ ```bash
133
+ npm install svger-cli --save-dev
134
+ ```
135
+
136
+ ### Usage
137
+
138
+ **rollup.config.js:**
139
+
140
+ ```javascript
141
+ import { svgerRollupPlugin } from 'svger-cli/rollup';
142
+
143
+ export default {
144
+ plugins: [
145
+ svgerRollupPlugin({
146
+ source: './src/icons',
147
+ output: './src/components/icons',
148
+ framework: 'react',
149
+ typescript: true,
150
+ sourcemap: true,
151
+ }),
152
+ ],
153
+ };
154
+ ```
155
+
156
+ ### Options
157
+
158
+ | Option | Type | Default | Description |
159
+ | ------------ | ------- | -------------------------- | ----------------------------------------- |
160
+ | `source` | string | `'./src/icons'` | Source directory containing SVG files |
161
+ | `output` | string | `'./src/components/icons'` | Output directory for generated components |
162
+ | `framework` | string | `'react'` | Target framework |
163
+ | `typescript` | boolean | `true` | Generate TypeScript files |
164
+ | `sourcemap` | boolean | `false` | Generate source maps |
165
+ | `exportType` | string | `'default'` | Export type ('default' or 'named') |
166
+
167
+ [See full example →](./examples/rollup.config.example.js)
168
+
169
+ ---
170
+
171
+ ## Babel Integration
172
+
173
+ ### Installation
174
+
175
+ ```bash
176
+ npm install svger-cli --save-dev
177
+ ```
178
+
179
+ ### Usage
180
+
181
+ **babel.config.js:**
182
+
183
+ ```javascript
184
+ const { svgerBabelPlugin } = require('svger-cli/babel');
185
+
186
+ module.exports = {
187
+ presets: ['@babel/preset-env', '@babel/preset-react'],
188
+ plugins: [
189
+ [
190
+ svgerBabelPlugin,
191
+ {
192
+ source: './src/icons',
193
+ output: './src/components/icons',
194
+ framework: 'react',
195
+ typescript: true,
196
+ transformImports: true,
197
+ processOnInit: true,
198
+ generateIndex: true,
199
+ },
200
+ ],
201
+ ],
202
+ };
203
+ ```
204
+
205
+ **Or with ES Modules (babel.config.mjs):**
206
+
207
+ ```javascript
208
+ import { svgerBabelPlugin } from 'svger-cli/babel';
209
+
210
+ export default {
211
+ presets: ['@babel/preset-react'],
212
+ plugins: [
213
+ [
214
+ svgerBabelPlugin,
215
+ {
216
+ source: './src/icons',
217
+ output: './src/components/icons',
218
+ framework: 'react',
219
+ },
220
+ ],
221
+ ],
222
+ };
223
+ ```
224
+
225
+ ### Features
226
+
227
+ - ✅ **Import Transformation** - Automatically transforms SVG imports to component imports
228
+ - ✅ **Dynamic Imports** - Supports `import('./icon.svg')` syntax
229
+ - ✅ **Auto-Processing** - Processes all SVGs when plugin initializes
230
+ - ✅ **Framework Agnostic** - Works with any Babel-based setup
231
+ - ✅ **TypeScript Support** - Full type definitions included
232
+
233
+ ### How It Works
234
+
235
+ ```javascript
236
+ // Before transformation
237
+ import HomeIcon from './assets/home.svg';
238
+
239
+ // After transformation (automatic)
240
+ import HomeIcon from './components/icons/HomeIcon';
241
+
242
+ // Use in your component
243
+ function App() {
244
+ return <HomeIcon width={24} height={24} />;
245
+ }
246
+ ```
247
+
248
+ ### Options
249
+
250
+ | Option | Type | Default | Description |
251
+ | ------------------ | ------- | -------------------------- | -------------------------------------------- |
252
+ | `source` | string | `'./src/icons'` | Source directory containing SVG files |
253
+ | `output` | string | `'./src/components/icons'` | Output directory for generated components |
254
+ | `framework` | string | `'react'` | Target framework (react, vue, angular, etc.) |
255
+ | `typescript` | boolean | `true` | Generate TypeScript files |
256
+ | `transformImports` | boolean | `true` | Transform SVG imports to component imports |
257
+ | `processOnInit` | boolean | `true` | Process all SVGs when plugin initializes |
258
+ | `generateIndex` | boolean | `true` | Generate index file with all exports |
259
+ | `include` | array | `['**/*.svg']` | Glob patterns to include |
260
+ | `exclude` | array | `['node_modules/**']` | Glob patterns to exclude |
261
+
262
+ ### Use Cases
263
+
264
+ **Create React App:**
265
+
266
+ ```javascript
267
+ // babel-plugin-macros.config.js
268
+ const { createBabelPlugin } = require('svger-cli/babel');
269
+
270
+ module.exports = {
271
+ svger: createBabelPlugin({
272
+ source: './src/icons',
273
+ framework: 'react',
274
+ }),
275
+ };
276
+ ```
277
+
278
+ **Gatsby:**
279
+
280
+ ```javascript
281
+ // gatsby-config.js
282
+ module.exports = {
283
+ plugins: [
284
+ {
285
+ resolve: 'gatsby-plugin-babel-plugin-svger',
286
+ options: {
287
+ source: './src/assets/icons',
288
+ framework: 'react',
289
+ },
290
+ },
291
+ ],
292
+ };
293
+ ```
294
+
295
+ **Vue CLI:**
296
+
297
+ ```javascript
298
+ // babel.config.js
299
+ const { svgerBabelPlugin } = require('svger-cli/babel');
300
+
301
+ module.exports = {
302
+ presets: ['@vue/cli-plugin-babel/preset'],
303
+ plugins: [
304
+ [
305
+ svgerBabelPlugin,
306
+ {
307
+ source: './src/assets/icons',
308
+ framework: 'vue',
309
+ },
310
+ ],
311
+ ],
312
+ };
313
+ ```
314
+
315
+ [See full example →](./examples/babel.config.example.js)
316
+
317
+ ---
318
+
319
+ ## Next.js Integration
320
+
321
+ ### Installation
322
+
323
+ ```bash
324
+ npm install svger-cli --save-dev
325
+ ```
326
+
327
+ ### Usage
328
+
329
+ **next.config.js:**
330
+
331
+ ```javascript
332
+ const { withSvger } = require('svger-cli/nextjs');
333
+
334
+ module.exports = withSvger({
335
+ svger: {
336
+ source: './public/icons',
337
+ output: './components/icons',
338
+ framework: 'react',
339
+ typescript: true,
340
+ ssr: true,
341
+ },
342
+ // ... other Next.js config
343
+ });
344
+ ```
345
+
346
+ ### Options
347
+
348
+ | Option | Type | Default | Description |
349
+ | ------------ | ------- | -------------------------- | ----------------------------------------- |
350
+ | `source` | string | `'./src/icons'` | Source directory containing SVG files |
351
+ | `output` | string | `'./src/components/icons'` | Output directory for generated components |
352
+ | `framework` | string | `'react'` | Always 'react' for Next.js |
353
+ | `typescript` | boolean | `true` | Generate TypeScript files |
354
+ | `ssr` | boolean | `true` | Enable Server-Side Rendering support |
355
+ | `hmr` | boolean | `true` | Enable Hot Module Replacement |
356
+
357
+ [See full example →](./examples/next.config.example.js)
358
+
359
+ ---
360
+
361
+ ## Jest Integration
362
+
363
+ ### Installation
364
+
365
+ ```bash
366
+ npm install svger-cli --save-dev
367
+ ```
368
+
369
+ ### Usage
370
+
371
+ **jest.config.js:**
372
+
373
+ ```javascript
374
+ module.exports = {
375
+ preset: 'svger-cli/jest',
376
+ testEnvironment: 'jsdom',
377
+ };
378
+ ```
379
+
380
+ **Or manually:**
381
+
382
+ ```javascript
383
+ module.exports = {
384
+ transform: {
385
+ '\\.svg$': 'svger-cli/jest-transformer',
386
+ },
387
+ };
388
+ ```
389
+
390
+ ### Options
391
+
392
+ Configure through transformer config:
393
+
394
+ ```javascript
395
+ transform: {
396
+ '\\.svg$': ['svger-cli/jest-transformer', {
397
+ framework: 'react',
398
+ typescript: true,
399
+ mock: false, // Use simple mocks for faster tests
400
+ }],
401
+ }
402
+ ```
403
+
404
+ [See full example →](./examples/jest.config.example.js)
405
+
406
+ ---
407
+
408
+ ## 🎯 Usage Examples
409
+
410
+ ### React Component
411
+
412
+ ```tsx
413
+ import { StarIcon, MenuIcon } from './components/icons';
414
+
415
+ function App() {
416
+ return (
417
+ <div>
418
+ <StarIcon width={24} height={24} fill="gold" />
419
+ <MenuIcon />
420
+ </div>
421
+ );
422
+ }
423
+ ```
424
+
425
+ ### Vue Component
426
+
427
+ ```vue
428
+ <template>
429
+ <div>
430
+ <StarIcon :width="24" :height="24" fill="gold" />
431
+ </div>
432
+ </template>
433
+
434
+ <script setup>
435
+ import { StarIcon } from './components/icons';
436
+ </script>
437
+ ```
438
+
439
+ ### Angular Component
440
+
441
+ ```typescript
442
+ import { Component } from '@angular/core';
443
+ import { StarIconComponent } from './components/icons';
444
+
445
+ @Component({
446
+ selector: 'app-root',
447
+ template: ` <app-star-icon [width]="24" [height]="24" fill="gold"></app-star-icon> `,
448
+ standalone: true,
449
+ imports: [StarIconComponent],
450
+ })
451
+ export class AppComponent {}
452
+ ```
453
+
454
+ ---
455
+
456
+ ## 🔧 Supported Frameworks
457
+
458
+ All integrations support these frameworks:
459
+
460
+ - ✅ React
461
+ - ✅ React Native
462
+ - ✅ Vue 3 (Composition & Options API)
463
+ - ✅ Angular (Standalone & Module)
464
+ - ✅ Svelte
465
+ - ✅ Solid
466
+ - ✅ Preact
467
+ - ✅ Lit
468
+ - ✅ Vanilla JS/TS
469
+
470
+ ---
471
+
472
+ ## 📚 Complete Examples
473
+
474
+ Explore full working examples in the [`examples/`](./examples/) directory:
475
+
476
+ - [Webpack Configuration](./examples/webpack.config.example.js)
477
+ - [Vite Configuration](./examples/vite.config.example.js)
478
+ - [Rollup Configuration](./examples/rollup.config.example.js)
479
+ - [Babel Configuration](./examples/babel.config.example.js)
480
+ - [Next.js Configuration](./examples/next.config.example.js)
481
+ - [Jest Configuration](./examples/jest.config.example.js)
482
+
483
+ ---
484
+
485
+ ## 🚀 Features
486
+
487
+ ### All Integrations Include:
488
+
489
+ - ✅ **Zero Dependencies** - No bloat
490
+ - ✅ **TypeScript Support** - Full type safety
491
+ - ✅ **Framework Agnostic** - Works with all major frameworks
492
+ - ✅ **Tree Shaking** - Bundle only what you use
493
+ - ✅ **Auto-Generated Exports** - Convenient barrel files
494
+ - ✅ **85% Faster** - Than alternatives like SVGR
495
+
496
+ ### Build Tool Specific:
497
+
498
+ | Feature | Webpack | Vite | Rollup | Babel | Next.js | Jest |
499
+ | ------------------ | ------- | ---- | ------ | ----- | ------- | ---- |
500
+ | HMR Support | ✅ | ✅ | ❌ | ❌ | ✅ | N/A |
501
+ | Source Maps | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
502
+ | SSR Support | ❌ | ✅ | ❌ | ❌ | ✅ | N/A |
503
+ | Virtual Modules | ❌ | ✅ | ❌ | ❌ | ❌ | N/A |
504
+ | Watch Mode | ✅ | ✅ | ✅ | ✅ | ✅ | N/A |
505
+ | Import Transform | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
506
+ | Dynamic Imports | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
507
+ | Framework Agnostic | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
508
+
509
+ ---
510
+
511
+ ## 🧪 Testing
512
+
513
+ Run integration tests:
514
+
515
+ ```bash
516
+ npm run test:integrations
517
+ ```
518
+
519
+ All integrations are thoroughly tested and verified to work correctly.
520
+
521
+ ---
522
+
523
+ ## 📖 Documentation
524
+
525
+ For complete documentation, visit the [main README](../README.md) or check out specific guides:
526
+
527
+ - [CLI Documentation](../README.md#-comprehensive-cli-reference)
528
+ - [Configuration Reference](../README.md#-configuration-reference)
529
+ - [API Documentation](../README.md#-programmatic-api)
530
+
531
+ ---
532
+
533
+ ## 💬 Support
534
+
535
+ - 📝 [Report Issues](https://github.com/navidrezadoost/svger-cli/issues)
536
+ - 💡 [Request Features](https://github.com/navidrezadoost/svger-cli/issues/new)
537
+ - 📖 [Read Docs](../README.md)
538
+
539
+ ---
540
+
541
+ ## 📄 License
542
+
543
+ MIT © SVGER-CLI Development Team
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Example Babel Configuration for SVGER-CLI
3
+ *
4
+ * This example shows how to use the SVGER Babel plugin to automatically
5
+ * convert SVG files to framework components during transpilation.
6
+ *
7
+ * The plugin works with any Babel-based build process including:
8
+ * - Standalone Babel
9
+ * - Create React App
10
+ * - Gatsby
11
+ * - Any tool using Babel under the hood
12
+ */
13
+
14
+ // Option 1: Using require (CommonJS)
15
+ const { svgerBabelPlugin } = require('svger-cli/babel');
16
+
17
+ module.exports = {
18
+ presets: [
19
+ '@babel/preset-env',
20
+ '@babel/preset-react',
21
+ '@babel/preset-typescript',
22
+ ],
23
+ plugins: [
24
+ // Add SVGER plugin with configuration
25
+ [
26
+ svgerBabelPlugin,
27
+ {
28
+ // Source directory containing SVG files
29
+ source: './src/icons',
30
+
31
+ // Output directory for generated components
32
+ output: './src/components/icons',
33
+
34
+ // Target framework
35
+ framework: 'react',
36
+
37
+ // Use TypeScript
38
+ typescript: true,
39
+
40
+ // Transform SVG imports to component imports
41
+ // When enabled: import Icon from './icon.svg' -> import Icon from './components/icons/Icon'
42
+ transformImports: true,
43
+
44
+ // Process all SVGs when plugin is initialized
45
+ // Recommended for production builds
46
+ processOnInit: true,
47
+
48
+ // Generate index file with all components
49
+ generateIndex: true,
50
+
51
+ // Glob patterns to include
52
+ include: ['**/*.svg'],
53
+
54
+ // Glob patterns to exclude
55
+ exclude: ['node_modules/**'],
56
+ },
57
+ ],
58
+ ],
59
+ };
60
+
61
+ // Option 2: Using ES Modules (in babel.config.mjs)
62
+ /*
63
+ import { svgerBabelPlugin } from 'svger-cli/babel';
64
+
65
+ export default {
66
+ presets: [
67
+ '@babel/preset-env',
68
+ '@babel/preset-react'
69
+ ],
70
+ plugins: [
71
+ [svgerBabelPlugin, {
72
+ source: './src/icons',
73
+ output: './src/components/icons',
74
+ framework: 'react',
75
+ typescript: true
76
+ }]
77
+ ]
78
+ };
79
+ */
80
+
81
+ // Option 3: Create React App (babel-plugin-macros.config.js)
82
+ /*
83
+ const { createBabelPlugin } = require('svger-cli/babel');
84
+
85
+ module.exports = {
86
+ svger: createBabelPlugin({
87
+ source: './src/icons',
88
+ output: './src/components/icons',
89
+ framework: 'react'
90
+ })
91
+ };
92
+ */
93
+
94
+ // Option 4: Minimal configuration (uses defaults from .svgerconfig)
95
+ /*
96
+ module.exports = {
97
+ presets: ['@babel/preset-react'],
98
+ plugins: [
99
+ // Simple usage - reads config from .svgerconfig
100
+ require('svger-cli/babel').svgerBabelPlugin
101
+ ]
102
+ };
103
+ */
104
+
105
+ // Option 5: Vue.js example
106
+ /*
107
+ const { svgerBabelPlugin } = require('svger-cli/babel');
108
+
109
+ module.exports = {
110
+ presets: ['@vue/cli-plugin-babel/preset'],
111
+ plugins: [
112
+ [svgerBabelPlugin, {
113
+ source: './src/assets/icons',
114
+ output: './src/components/icons',
115
+ framework: 'vue',
116
+ typescript: false
117
+ }]
118
+ ]
119
+ };
120
+ */
121
+
122
+ // Option 6: Angular example
123
+ /*
124
+ const { svgerBabelPlugin } = require('svger-cli/babel');
125
+
126
+ module.exports = {
127
+ presets: ['@babel/preset-typescript'],
128
+ plugins: [
129
+ [svgerBabelPlugin, {
130
+ source: './src/assets/svg',
131
+ output: './src/app/components/icons',
132
+ framework: 'angular',
133
+ typescript: true
134
+ }]
135
+ ]
136
+ };
137
+ */
138
+
139
+ /**
140
+ * Configuration Options Reference:
141
+ *
142
+ * @param {string} source - Source directory containing SVG files
143
+ * @param {string} output - Output directory for generated components
144
+ * @param {string} framework - Target framework (react, vue, angular, svelte, etc.)
145
+ * @param {boolean} typescript - Generate TypeScript files (.tsx instead of .jsx)
146
+ * @param {boolean} transformImports - Transform SVG imports to component imports
147
+ * @param {boolean} processOnInit - Process all SVGs when plugin initializes
148
+ * @param {boolean} generateIndex - Generate index.ts/js with all exports
149
+ * @param {string|string[]} include - Glob patterns to include
150
+ * @param {string|string[]} exclude - Glob patterns to exclude
151
+ * @param {object} config - Advanced configuration (see .svgerconfig docs)
152
+ *
153
+ * Features:
154
+ * - ✅ Automatic SVG to component conversion during build
155
+ * - ✅ Import transformation (import Icon from './icon.svg')
156
+ * - ✅ Dynamic import support (import('./icon.svg'))
157
+ * - ✅ Framework-agnostic (React, Vue, Angular, Svelte, etc.)
158
+ * - ✅ TypeScript support with type definitions
159
+ * - ✅ Auto-generated barrel exports (index files)
160
+ * - ✅ Watch mode compatible
161
+ * - ✅ Works with Create React App, Gatsby, and more
162
+ *
163
+ * How it works:
164
+ * 1. Plugin processes all SVGs in source directory on initialization
165
+ * 2. Generates framework-specific components in output directory
166
+ * 3. Transforms SVG imports in your code to component imports
167
+ * 4. Creates index file with all component exports
168
+ *
169
+ * Usage in your code:
170
+ * ```jsx
171
+ * // Before (with transformImports: true)
172
+ * import HomeIcon from './assets/home.svg';
173
+ *
174
+ * // After transformation (automatic)
175
+ * import HomeIcon from './components/icons/HomeIcon';
176
+ *
177
+ * // Use the component
178
+ * function App() {
179
+ * return <HomeIcon width={24} height={24} />;
180
+ * }
181
+ * ```
182
+ */