A Visual Studio Code extension for editing SVG files with live preview and integrated optimization.
- β¨ Editor with side preview: Edit your SVG in a textarea with real-time preview in the Explorer panel
- π¨ currentColor control: Change the
currentColorvalue to preview different color schemes - π Dark background: Toggle dark background to better visualize SVGs with light colors
- π Zoom and pan: Zoom in/out with click or Alt+click, scroll with Alt, and drag to pan
- β‘ SVGO optimization: Integrated toolbar button to optimize your SVG
- π Grid background: Preview includes a grid background to better see transparent SVGs
- Open any
.svgfile - The extension will automatically open the custom editor with:
- Code editor taking up the full panel
- Preview panel
- Click the β‘ icon in the toolbar to optimize the SVG
- Drag panel: Click on the "Preview" header and drag
- Resize: Use the resize handle in the bottom right corner
- Zoom in: Normal click on the preview
- Zoom out: Hold Alt + Click
- Zoom with scroll: Hold Alt + use mouse wheel
- Pan: When zoomed, drag the SVG with left button
- Change currentColor: Click the palette icon + color circle
- Dark background: Click the moon icon
The extension includes the following configurable options (accessible from Settings β Extensions β Better SVG):
- Type:
boolean - Default value:
true - Description: Automatically expand the "SVG Preview" panel in Explorer when opening an SVG file. If disabled, you'll need to manually open the panel each time.
- Type:
boolean - Default value:
true - Description: Automatically collapse the "SVG Preview" panel when closing all SVG files or switching to a non-SVG file. If disabled, the panel will remain open even when no SVG files are active.
- Type:
string - Default value:
"#ffffff" - Description: Default color for
currentColorin the SVG preview. Must be a valid hexadecimal color (e.g.,#ffffff,#000,#ff5733). This color will be applied when opening an SVG file and can be manually changed using the color picker in the preview panel.
{
"betterSvg.autoReveal": true,
"betterSvg.autoCollapse": true,
"betterSvg.defaultColor": "#ffffff"
}better-svg/
βββ src/
β βββ extension.ts # Extension entry point
β βββ svgEditorProvider.ts # Custom editor provider
β βββ webview/ # Webview files
β βββ index.html # HTML template
β βββ styles.css # CSS styles
β βββ main.js # Webview JavaScript logic
βββ package.json
cd better-svg
npm install
npm run compileThen press F5 in VS Code to open an extension window for testing.
# Single compilation
npm run compile
# Watch mode (automatically recompiles on save)
npm run watch# Optimized production build (minified)
npm run packageThe extension uses esbuild for bundling, which means:
- β Faster: Bundle loads instantly
- β Smaller: ~500KB vs multiple files
- β Web compatible: Works on github.dev and vscode.dev
- β Type checking: TypeScript verifies types without emitting files
npm install -g @vscode/vsce
vsce packageThis will create a .vsix file that can be installed or published to the marketplace.