Skip to content

Converts text files to modules. Such as .vs, .fs, .vert, .frag, .glsl, .wgsl etc.

License

Notifications You must be signed in to change notification settings

aweikalee/vite-plugin-string

Repository files navigation

Vite Plugin String

Converts text files to modules. Such as .vs, .fs, .vert, .frag, .glsl, wgsl etc.

import fragment from './fragment.glsl'
console.log(fragment)

Preface

Most cases, you don't need this plugin.

vite already supports suffix ?raw, import as string.

import fragment from './fragment.glsl?raw'

Installation

npm install --save-dev vite-plugin-string

If you are using vite@1.0.0, please install vite-plugin-string@0.0.2.

Usage

// vite.config.js
import vitePluginString from 'vite-plugin-string'

export default {
  plugins: [
    vitePluginString()
  ]
}

Options

vitePluginString(options)
{
  /* Default */
  include: [
    '**/*.vs',
    '**/*.fs',
    '**/*.vert',
    '**/*.frag',
    '**/*.glsl',
    '**/*.wgsl',
  ],

  /* Default: undefined */
  exclude: 'node_modules/**',

  /* Default: true */
  // if true, using logic from rollup-plugin-glsl
  compress: true,

  // if a function, will instead of default compress function
  // returns string|Promise<string>
  compress(code) {
    return code.replace(/\n/g, '')
  }
}