vite-plugin-virtual-plain-text
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    vite-plugin-virtual-plain-text

    NPM

    publish workflow npm version

    A Vite plugin loads file as plain text from the virtual assets workspace.

    This plugin resolves a virtual assets path file as a local file path against the project root.

    Install

    yarn add -D vite-plugin-virtual-plain-text (or by npm)

    Example

    Take the project's legal file LICENSE as an example:

    // vite.config.(t|j)s
    
    import { defineConfig } from 'vite';
    
    import plainText from 'vite-plugin-virtual-plain-text';
    
    export default defineConfig({
      plugins: [
        // passing string type Regular expression
        plainText(),
      ],
    });

    Load the content of LICENSE file under the project root:

    // component.js
    
    import { plainText as LICENSE } from '@virtual:plain-text/LICENSE'
    
    console.log(LICENSE)

    For Typescript user you could add the typing reference in your workspace declaration file:

    // declaration.d.ts
    /// <reference types="vite-plugin-virtual-plain-text/virtual-assets" />

    Advanced

    You can configure the virtual assets' workspace name

    // vite.config.(t|j)s
    
    import { defineConfig } from 'vite';
    
    import plainText from 'vite-plugin-virtual-plain-text';
    
    export default defineConfig({
      plugins: [
        // passing string type Regular expression
        plainText('@my-virtual-plain-text-workspace:/'),
      ],
    });

    For Typescript user, the type declaration should be correspondingly added:

    // declaration.d.ts
    
    declare module '@my-virtual-plain-text-workspace:/*' {
        export const plainText: string
    }

    License

    MIT

    Alternative

    Plain text transformer: vite-plugin-plain-text

    Install

    npm i vite-plugin-virtual-plain-text

    DownloadsWeekly Downloads

    12

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    5.24 kB

    Total Files

    6

    Last publish

    Collaborators

    • zheeeng