Converts text files to modules. Such as .vs, .fs, .vert, .frag, .glsl, wgsl etc.
import fragment from './fragment.glsl'
console.log(fragment)
Most cases, you don't need this plugin.
vite
already supports suffix ?raw
, import as string.
import fragment from './fragment.glsl?raw'
npm install --save-dev vite-plugin-string
If you are using
[email protected]
, please install[email protected]
.
// vite.config.js
import vitePluginString from 'vite-plugin-string'
export default {
plugins: [
vitePluginString()
]
}
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, '')
}
}