vite-string-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.4.4 • Public • Published

vite-string-plugin

Vite plugin to import files as string, with zero dependencies

Usage

vite.config.js

import {defineConfig} from "vite";
import {stringPlugin} from "vite-string-plugin";

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

file.js

import foo from "./foo.svg";

Options

  • match: Regex to match the path against. Default: /\.(svg|md|xml|txt)$/i.

Typescript

If the default file extensions cover your needs, add vite-string-plugin/types to your types in tsconfig.json:

{
  "compilerOptions": {
    "types": [
      "vite-string-plugin/types"
    ]
  }
}

Alternatively, you can add ambient type declarations for each file extension:

declare module "*.svg" {
  const value: string;
  export default value;
}
declare module "*.md" {
  const value: string;
  export default value;
}
declare module "*.xml" {
  const value: string;
  export default value;
}
declare module "*.txt" {
  const value: string;
  export default value;
}

Related

/vite-string-plugin/

    Package Sidebar

    Install

    npm i vite-string-plugin

    Weekly Downloads

    1,808

    Version

    1.4.4

    License

    BSD-2-Clause

    Unpacked Size

    5.06 kB

    Total Files

    7

    Last publish

    Collaborators

    • silverwind