Skip to content

transform a js/jsx/ts string #20102

Open
@huseeiin

Description

@huseeiin

Description

import { defineConfig, type Plugin } from "vite";
import { extname } from "node:path";

// convert svg to jsx
function svg(): Plugin {
  return {
    name: "svg",

    async transform(code, id) {
      if (extname(id) === ".svg") {
        return this.transformJsxOrTs(
          `export default () => ${decodeURIComponent(code)
            .replace('export default "data:image/svg+xml,', "")
            .replace('"', "")}`
        );
      }
    },
  };
}

Suggested solution

ability to run vite's internal transformer with all the user's plugins

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions