Skip to content

A wmr plugin to load svg files as preact components.

License

Notifications You must be signed in to change notification settings

RodrigoJuliano/wmr-svg-loader

 
 

Repository files navigation

wmr-svg-loader: WIP

A port of preact-svg-loader to wmr. Load svg files as preact components.

Install

npm i --save-dev wmr-svg-loader

or

yarn add --dev wmr-svg-loader

Usage

Add the plugin to your wmr.config.mjs.

import { defineConfig } from 'wmr';
import svgLoaderPlugin from 'wmr-svg-loader';

export default defineConfig({
  plugins: [svgLoaderPlugin()],
});

In your code, use the prefix svg: to import the svg as a component.

import Logo from 'svg:./logo.svg';

() => <Logo />

The prefix is customizable.

plugins: [svgLoaderPlugin({ importPrefix: 'myprefix:' })],

You can also use in combination with lazy to enable code spliting, generating a js file to each svg.

import { lazy, ErrorBoundary } from 'preact-iso';

const Logo = lazy(() => import('svg:./logo.svg'));

() => (
    <ErrorBoundary>
        <Logo />
    <ErrorBoundary/>
);

About

A wmr plugin to load svg files as preact components.

Resources

License

Stars

Watchers

Forks

Languages

  • JavaScript 100.0%