Skip to content

Vite plugin to import files as string, with zero dependencies

License

Notifications You must be signed in to change notification settings

silverwind/vite-string-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

80b4aad · Apr 5, 2025
May 2, 2024
Jul 25, 2023
Jul 7, 2023
Jan 26, 2025
Jul 7, 2023
Apr 29, 2024
Jul 7, 2023
Feb 14, 2025
May 2, 2024
Jan 16, 2025
Apr 29, 2024
Apr 5, 2025
Feb 14, 2025
Feb 14, 2025
Jan 16, 2025
Jan 16, 2025
Apr 29, 2024
Jun 13, 2024
Feb 14, 2025

Repository files navigation

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

About

Vite plugin to import files as string, with zero dependencies

Resources

License

Stars

Watchers

Forks

Packages

No packages published