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.
- package/CHANGELOG.md +259 -9
- package/README.md +383 -13
- package/dist/index.d.ts +30 -0
- package/dist/index.js +33 -0
- package/dist/integrations/babel.d.ts +58 -0
- package/dist/integrations/babel.js +221 -0
- package/dist/integrations/jest-preset.d.ts +44 -0
- package/dist/integrations/jest-preset.js +169 -0
- package/dist/integrations/nextjs.d.ts +56 -0
- package/dist/integrations/nextjs.js +140 -0
- package/dist/integrations/rollup.d.ts +29 -0
- package/dist/integrations/rollup.js +197 -0
- package/dist/integrations/vite.d.ts +29 -0
- package/dist/integrations/vite.js +221 -0
- package/dist/integrations/webpack.d.ts +84 -0
- package/dist/integrations/webpack.js +273 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -1
- package/dist/types/integrations.d.ts +255 -0
- package/dist/types/integrations.js +4 -0
- package/docs/INTEGRATION-IMPLEMENTATION-SUMMARY.md +448 -0
- package/docs/INTEGRATIONS.md +543 -0
- package/examples/babel.config.example.js +182 -0
- package/examples/jest.config.example.js +158 -0
- package/examples/next.config.example.js +133 -0
- package/examples/rollup.config.example.js +129 -0
- package/examples/vite.config.example.js +98 -0
- package/examples/webpack.config.example.js +88 -0
- package/package.json +75 -5
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest Configuration Example with SVGER-CLI
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to use SVGER-CLI with Jest for testing
|
|
5
|
+
* components that use SVG imports.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Method 1: Using the preset (Recommended)
|
|
10
|
+
*/
|
|
11
|
+
module.exports = {
|
|
12
|
+
preset: 'svger-cli/jest',
|
|
13
|
+
|
|
14
|
+
testEnvironment: 'jsdom',
|
|
15
|
+
|
|
16
|
+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
|
17
|
+
|
|
18
|
+
moduleNameMapper: {
|
|
19
|
+
'^@/(.*)$': '<rootDir>/src/$1',
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Method 2: Manual configuration
|
|
27
|
+
*/
|
|
28
|
+
const manualConfig = {
|
|
29
|
+
testEnvironment: 'jsdom',
|
|
30
|
+
|
|
31
|
+
transform: {
|
|
32
|
+
// Transform SVG files to components
|
|
33
|
+
'\\.svg$': 'svger-cli/jest-transformer',
|
|
34
|
+
|
|
35
|
+
// Transform JS/TS files
|
|
36
|
+
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
transformIgnorePatterns: ['node_modules/(?!(svger-cli)/)'],
|
|
40
|
+
|
|
41
|
+
moduleNameMapper: {
|
|
42
|
+
'\\.svg$': 'svger-cli/jest-transformer',
|
|
43
|
+
'^@/(.*)$': '<rootDir>/src/$1',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// module.exports = manualConfig;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Method 3: Custom transformer with options
|
|
51
|
+
*/
|
|
52
|
+
const { createJestTransformer } = require('svger-cli/jest-preset');
|
|
53
|
+
|
|
54
|
+
const customConfig = {
|
|
55
|
+
testEnvironment: 'jsdom',
|
|
56
|
+
|
|
57
|
+
transform: {
|
|
58
|
+
'\\.svg$': [
|
|
59
|
+
'svger-cli/jest-transformer',
|
|
60
|
+
{
|
|
61
|
+
framework: 'react',
|
|
62
|
+
typescript: true,
|
|
63
|
+
mock: false, // Set to true for simple mocks
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// module.exports = customConfig;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Usage in tests:
|
|
73
|
+
*
|
|
74
|
+
* // MyComponent.test.tsx
|
|
75
|
+
* import React from 'react';
|
|
76
|
+
* import { render, screen } from '@testing-library/react';
|
|
77
|
+
* import { StarIcon } from '@/components/icons';
|
|
78
|
+
* import Logo from './logo.svg';
|
|
79
|
+
*
|
|
80
|
+
* describe('Icon Components', () => {
|
|
81
|
+
* it('renders StarIcon correctly', () => {
|
|
82
|
+
* render(<StarIcon width={24} height={24} fill="gold" />);
|
|
83
|
+
* const svg = screen.getByRole('img', { hidden: true });
|
|
84
|
+
* expect(svg).toBeInTheDocument();
|
|
85
|
+
* expect(svg).toHaveAttribute('width', '24');
|
|
86
|
+
* expect(svg).toHaveAttribute('fill', 'gold');
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* it('renders Logo correctly', () => {
|
|
90
|
+
* render(<Logo width={50} height={50} />);
|
|
91
|
+
* const svg = screen.getByRole('img', { hidden: true });
|
|
92
|
+
* expect(svg).toBeInTheDocument();
|
|
93
|
+
* });
|
|
94
|
+
* });
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* jest.setup.js example:
|
|
99
|
+
*
|
|
100
|
+
* import '@testing-library/jest-dom';
|
|
101
|
+
*
|
|
102
|
+
* // Mock IntersectionObserver if needed
|
|
103
|
+
* global.IntersectionObserver = class IntersectionObserver {
|
|
104
|
+
* constructor() {}
|
|
105
|
+
* disconnect() {}
|
|
106
|
+
* observe() {}
|
|
107
|
+
* takeRecords() { return []; }
|
|
108
|
+
* unobserve() {}
|
|
109
|
+
* };
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* TypeScript configuration (tsconfig.json):
|
|
114
|
+
*
|
|
115
|
+
* {
|
|
116
|
+
* "compilerOptions": {
|
|
117
|
+
* "types": ["jest", "@testing-library/jest-dom"],
|
|
118
|
+
* "esModuleInterop": true
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Using mock mode for faster tests:
|
|
125
|
+
*
|
|
126
|
+
* When you don't need to test SVG internals, use mock mode
|
|
127
|
+
* for faster test execution:
|
|
128
|
+
*/
|
|
129
|
+
const mockConfig = {
|
|
130
|
+
testEnvironment: 'jsdom',
|
|
131
|
+
|
|
132
|
+
transform: {
|
|
133
|
+
'\\.svg$': [
|
|
134
|
+
'svger-cli/jest-transformer',
|
|
135
|
+
{
|
|
136
|
+
mock: true, // Creates simple React component mocks
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// module.exports = mockConfig;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Testing with Vitest:
|
|
146
|
+
*
|
|
147
|
+
* // vitest.config.ts
|
|
148
|
+
* import { defineConfig } from 'vitest/config';
|
|
149
|
+
* import { svgerVitePlugin } from 'svger-cli/vite';
|
|
150
|
+
*
|
|
151
|
+
* export default defineConfig({
|
|
152
|
+
* plugins: [svgerVitePlugin()],
|
|
153
|
+
* test: {
|
|
154
|
+
* environment: 'jsdom',
|
|
155
|
+
* setupFiles: './vitest.setup.ts',
|
|
156
|
+
* },
|
|
157
|
+
* });
|
|
158
|
+
*/
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Configuration Example with SVGER-CLI
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to use SVGER-CLI with Next.js for automatic
|
|
5
|
+
* SVG to component conversion with SSR support.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { withSvger } = require('svger-cli/nextjs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Method 1: Using withSvger wrapper (Recommended)
|
|
12
|
+
*/
|
|
13
|
+
module.exports = withSvger({
|
|
14
|
+
// SVGER-CLI configuration
|
|
15
|
+
svger: {
|
|
16
|
+
source: './public/icons', // Source directory with SVG files
|
|
17
|
+
output: './components/icons', // Output directory for components
|
|
18
|
+
framework: 'react', // Always 'react' for Next.js
|
|
19
|
+
typescript: true, // Generate TypeScript files
|
|
20
|
+
hmr: true, // Enable Hot Module Replacement
|
|
21
|
+
ssr: true, // Enable Server-Side Rendering support
|
|
22
|
+
generateIndex: true, // Generate index.ts with all exports
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Standard Next.js configuration
|
|
26
|
+
reactStrictMode: true,
|
|
27
|
+
swcMinify: true,
|
|
28
|
+
|
|
29
|
+
images: {
|
|
30
|
+
domains: ['example.com'],
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// Optional: Custom webpack configuration
|
|
34
|
+
// webpack: (config, options) => {
|
|
35
|
+
// // Your custom webpack config here
|
|
36
|
+
// return config;
|
|
37
|
+
// },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Method 2: Manual webpack integration
|
|
42
|
+
*/
|
|
43
|
+
const { SvgerNextJsPlugin } = require('svger-cli/nextjs');
|
|
44
|
+
|
|
45
|
+
const manualConfig = {
|
|
46
|
+
reactStrictMode: true,
|
|
47
|
+
|
|
48
|
+
webpack(config, options) {
|
|
49
|
+
// Add SVGER plugin
|
|
50
|
+
config.plugins.push(
|
|
51
|
+
new SvgerNextJsPlugin({
|
|
52
|
+
source: './public/icons',
|
|
53
|
+
output: './components/icons',
|
|
54
|
+
framework: 'react',
|
|
55
|
+
typescript: true,
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return config;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// module.exports = manualConfig;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Method 3: Using configureSvgImports helper
|
|
67
|
+
*/
|
|
68
|
+
const { configureSvgImports } = require('svger-cli/nextjs');
|
|
69
|
+
|
|
70
|
+
const helperConfig = {
|
|
71
|
+
reactStrictMode: true,
|
|
72
|
+
|
|
73
|
+
webpack(config, options) {
|
|
74
|
+
// Configure SVG imports
|
|
75
|
+
configureSvgImports(config, {
|
|
76
|
+
framework: 'react',
|
|
77
|
+
typescript: true,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return config;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// module.exports = helperConfig;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Usage in your Next.js pages/components:
|
|
88
|
+
*
|
|
89
|
+
* // pages/index.tsx
|
|
90
|
+
* import { StarIcon, MenuIcon, LogoIcon } from '@/components/icons';
|
|
91
|
+
* import type { NextPage } from 'next';
|
|
92
|
+
*
|
|
93
|
+
* const Home: NextPage = () => {
|
|
94
|
+
* return (
|
|
95
|
+
* <div>
|
|
96
|
+
* <LogoIcon width={100} height={100} />
|
|
97
|
+
* <StarIcon fill="gold" className="star" />
|
|
98
|
+
* <MenuIcon />
|
|
99
|
+
* </div>
|
|
100
|
+
* );
|
|
101
|
+
* };
|
|
102
|
+
*
|
|
103
|
+
* export default Home;
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* App Router (Next.js 13+):
|
|
108
|
+
*
|
|
109
|
+
* // app/page.tsx
|
|
110
|
+
* import { StarIcon } from '@/components/icons';
|
|
111
|
+
*
|
|
112
|
+
* export default function Page() {
|
|
113
|
+
* return (
|
|
114
|
+
* <main>
|
|
115
|
+
* <StarIcon width={24} height={24} />
|
|
116
|
+
* </main>
|
|
117
|
+
* );
|
|
118
|
+
* }
|
|
119
|
+
*
|
|
120
|
+
* // The icons work seamlessly with Server Components!
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* TypeScript paths configuration (tsconfig.json):
|
|
125
|
+
*
|
|
126
|
+
* {
|
|
127
|
+
* "compilerOptions": {
|
|
128
|
+
* "paths": {
|
|
129
|
+
* "@/components/*": ["./components/*"]
|
|
130
|
+
* }
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
*/
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rollup Configuration Example with SVGER-CLI
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to use SVGER-CLI with Rollup for automatic
|
|
5
|
+
* SVG to component conversion with tree-shaking support.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { svgerRollupPlugin } from 'svger-cli/rollup';
|
|
9
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
10
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
11
|
+
import babel from '@rollup/plugin-babel';
|
|
12
|
+
import terser from '@rollup/plugin-terser';
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
input: 'src/index.js',
|
|
16
|
+
|
|
17
|
+
output: [
|
|
18
|
+
{
|
|
19
|
+
file: 'dist/bundle.js',
|
|
20
|
+
format: 'iife',
|
|
21
|
+
name: 'MyApp',
|
|
22
|
+
sourcemap: true,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
file: 'dist/bundle.esm.js',
|
|
26
|
+
format: 'esm',
|
|
27
|
+
sourcemap: true,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
plugins: [
|
|
32
|
+
// SVGER-CLI Rollup Plugin - Convert SVGs to components
|
|
33
|
+
svgerRollupPlugin({
|
|
34
|
+
source: './src/icons', // Source directory with SVG files
|
|
35
|
+
output: './src/components/icons', // Output directory for components
|
|
36
|
+
framework: 'react', // Framework: react, vue, svelte, etc.
|
|
37
|
+
typescript: true, // Generate TypeScript files
|
|
38
|
+
generateIndex: true, // Generate index.ts with all exports
|
|
39
|
+
sourcemap: true, // Generate source maps
|
|
40
|
+
|
|
41
|
+
// Optional: Export type
|
|
42
|
+
exportType: 'default', // 'default' or 'named'
|
|
43
|
+
|
|
44
|
+
// Optional: SVGO optimization
|
|
45
|
+
svgo: true,
|
|
46
|
+
}),
|
|
47
|
+
|
|
48
|
+
// Resolve node modules
|
|
49
|
+
resolve({
|
|
50
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
51
|
+
}),
|
|
52
|
+
|
|
53
|
+
// Convert CommonJS modules to ES6
|
|
54
|
+
commonjs(),
|
|
55
|
+
|
|
56
|
+
// Transpile with Babel
|
|
57
|
+
babel({
|
|
58
|
+
babelHelpers: 'bundled',
|
|
59
|
+
exclude: 'node_modules/**',
|
|
60
|
+
presets: ['@babel/preset-env', '@babel/preset-react'],
|
|
61
|
+
}),
|
|
62
|
+
|
|
63
|
+
// Minify for production
|
|
64
|
+
process.env.NODE_ENV === 'production' && terser(),
|
|
65
|
+
],
|
|
66
|
+
|
|
67
|
+
external: ['react', 'react-dom'],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Usage in your code:
|
|
72
|
+
*
|
|
73
|
+
* // Import from generated components
|
|
74
|
+
* import { StarIcon, MenuIcon } from './components/icons';
|
|
75
|
+
*
|
|
76
|
+
* // Or import SVG directly (transformed by plugin)
|
|
77
|
+
* import Logo from './assets/logo.svg';
|
|
78
|
+
*
|
|
79
|
+
* function App() {
|
|
80
|
+
* return (
|
|
81
|
+
* <div>
|
|
82
|
+
* <Logo width={50} height={50} />
|
|
83
|
+
* <StarIcon fill="gold" />
|
|
84
|
+
* <MenuIcon />
|
|
85
|
+
* </div>
|
|
86
|
+
* );
|
|
87
|
+
* }
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Library Build Configuration:
|
|
92
|
+
*
|
|
93
|
+
* For building a component library with icons:
|
|
94
|
+
*/
|
|
95
|
+
export const libraryConfig = {
|
|
96
|
+
input: 'src/index.js',
|
|
97
|
+
|
|
98
|
+
output: [
|
|
99
|
+
{
|
|
100
|
+
file: 'dist/index.js',
|
|
101
|
+
format: 'cjs',
|
|
102
|
+
exports: 'named',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
file: 'dist/index.esm.js',
|
|
106
|
+
format: 'esm',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
|
|
110
|
+
plugins: [
|
|
111
|
+
svgerRollupPlugin({
|
|
112
|
+
source: './src/icons',
|
|
113
|
+
output: './src/components/icons',
|
|
114
|
+
framework: 'react',
|
|
115
|
+
typescript: true,
|
|
116
|
+
generateIndex: true,
|
|
117
|
+
exportType: 'named', // Better for libraries
|
|
118
|
+
}),
|
|
119
|
+
|
|
120
|
+
resolve(),
|
|
121
|
+
commonjs(),
|
|
122
|
+
babel({
|
|
123
|
+
babelHelpers: 'runtime',
|
|
124
|
+
exclude: 'node_modules/**',
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
127
|
+
|
|
128
|
+
external: ['react', 'react-dom', '@babel/runtime'],
|
|
129
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite Configuration Example with SVGER-CLI
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to use SVGER-CLI with Vite for automatic
|
|
5
|
+
* SVG to component conversion with HMR and virtual modules.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { defineConfig } from 'vite';
|
|
9
|
+
import react from '@vitejs/plugin-react';
|
|
10
|
+
import { svgerVitePlugin } from 'svger-cli/vite';
|
|
11
|
+
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
plugins: [
|
|
14
|
+
react(),
|
|
15
|
+
|
|
16
|
+
// SVGER-CLI Vite Plugin
|
|
17
|
+
svgerVitePlugin({
|
|
18
|
+
source: './src/icons', // Source directory with SVG files
|
|
19
|
+
output: './src/components/icons', // Output directory for components
|
|
20
|
+
framework: 'react', // Framework: react, vue, svelte, etc.
|
|
21
|
+
typescript: true, // Generate TypeScript files
|
|
22
|
+
hmr: true, // Enable Hot Module Replacement
|
|
23
|
+
generateIndex: true, // Generate index.ts with all exports
|
|
24
|
+
|
|
25
|
+
// Optional: Use virtual modules (experimental)
|
|
26
|
+
virtual: false,
|
|
27
|
+
|
|
28
|
+
// Optional: Export type
|
|
29
|
+
exportType: 'default', // 'default' or 'named'
|
|
30
|
+
|
|
31
|
+
// Optional: SVGO optimization
|
|
32
|
+
svgo: false,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
|
|
36
|
+
server: {
|
|
37
|
+
port: 3000,
|
|
38
|
+
open: true,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
build: {
|
|
42
|
+
outDir: 'dist',
|
|
43
|
+
sourcemap: true,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Usage in your code (React example):
|
|
49
|
+
*
|
|
50
|
+
* // Import from generated components
|
|
51
|
+
* import { StarIcon, MenuIcon, HomeIcon } from './components/icons';
|
|
52
|
+
*
|
|
53
|
+
* // Or import SVG directly (transformed by plugin)
|
|
54
|
+
* import Logo from './assets/logo.svg';
|
|
55
|
+
*
|
|
56
|
+
* function App() {
|
|
57
|
+
* return (
|
|
58
|
+
* <div>
|
|
59
|
+
* <Logo width={50} height={50} fill="currentColor" />
|
|
60
|
+
* <StarIcon width={24} height={24} fill="gold" />
|
|
61
|
+
* <MenuIcon className="menu-icon" />
|
|
62
|
+
* <HomeIcon />
|
|
63
|
+
* </div>
|
|
64
|
+
* );
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* // With virtual modules (if enabled)
|
|
68
|
+
* import StarIcon from 'virtual:svger/star-icon';
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Usage with Vue:
|
|
73
|
+
*
|
|
74
|
+
* // vite.config.js
|
|
75
|
+
* import vue from '@vitejs/plugin-vue';
|
|
76
|
+
* import { svgerVitePlugin } from 'svger-cli/vite';
|
|
77
|
+
*
|
|
78
|
+
* export default defineConfig({
|
|
79
|
+
* plugins: [
|
|
80
|
+
* vue(),
|
|
81
|
+
* svgerVitePlugin({
|
|
82
|
+
* framework: 'vue',
|
|
83
|
+
* typescript: true,
|
|
84
|
+
* }),
|
|
85
|
+
* ],
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // In your Vue component
|
|
89
|
+
* <template>
|
|
90
|
+
* <div>
|
|
91
|
+
* <StarIcon :width="24" :height="24" fill="gold" />
|
|
92
|
+
* </div>
|
|
93
|
+
* </template>
|
|
94
|
+
*
|
|
95
|
+
* <script setup>
|
|
96
|
+
* import { StarIcon } from './components/icons';
|
|
97
|
+
* </script>
|
|
98
|
+
*/
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack Configuration Example with SVGER-CLI
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to use SVGER-CLI with Webpack for automatic
|
|
5
|
+
* SVG to component conversion with HMR support.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { SvgerWebpackPlugin } = require('svger-cli/webpack');
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
mode: 'development',
|
|
13
|
+
entry: './src/index.js',
|
|
14
|
+
output: {
|
|
15
|
+
path: path.resolve(__dirname, 'dist'),
|
|
16
|
+
filename: 'bundle.js',
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
module: {
|
|
20
|
+
rules: [
|
|
21
|
+
{
|
|
22
|
+
test: /\.jsx?$/,
|
|
23
|
+
exclude: /node_modules/,
|
|
24
|
+
use: 'babel-loader',
|
|
25
|
+
},
|
|
26
|
+
// SVGER-CLI Loader - Transform SVG imports inline
|
|
27
|
+
{
|
|
28
|
+
test: /\.svg$/,
|
|
29
|
+
use: [
|
|
30
|
+
{
|
|
31
|
+
loader: 'svger-cli/webpack-loader',
|
|
32
|
+
options: {
|
|
33
|
+
framework: 'react',
|
|
34
|
+
typescript: false, // Set to true if using TypeScript
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
plugins: [
|
|
43
|
+
// SVGER-CLI Plugin - Batch convert SVGs at build time
|
|
44
|
+
new SvgerWebpackPlugin({
|
|
45
|
+
source: './src/icons', // Source directory with SVG files
|
|
46
|
+
output: './src/components/icons', // Output directory for components
|
|
47
|
+
framework: 'react', // Framework: react, vue, angular, etc.
|
|
48
|
+
typescript: false, // Generate TypeScript files
|
|
49
|
+
hmr: true, // Enable Hot Module Replacement
|
|
50
|
+
generateIndex: true, // Generate index.js with all exports
|
|
51
|
+
watch: {
|
|
52
|
+
debounce: 300, // Debounce delay for file changes
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
|
|
57
|
+
devServer: {
|
|
58
|
+
port: 3000,
|
|
59
|
+
hot: true,
|
|
60
|
+
static: {
|
|
61
|
+
directory: path.join(__dirname, 'public'),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
resolve: {
|
|
66
|
+
extensions: ['.js', '.jsx', '.json'],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Usage in your code:
|
|
72
|
+
*
|
|
73
|
+
* // Import from generated components
|
|
74
|
+
* import { StarIcon, MenuIcon } from './components/icons';
|
|
75
|
+
*
|
|
76
|
+
* // Or import SVG directly (transformed by loader)
|
|
77
|
+
* import Logo from './assets/logo.svg';
|
|
78
|
+
*
|
|
79
|
+
* function App() {
|
|
80
|
+
* return (
|
|
81
|
+
* <div>
|
|
82
|
+
* <Logo width={50} height={50} />
|
|
83
|
+
* <StarIcon fill="gold" />
|
|
84
|
+
* <MenuIcon />
|
|
85
|
+
* </div>
|
|
86
|
+
* );
|
|
87
|
+
* }
|
|
88
|
+
*/
|