NPM Star
Collections
  1. Home
  2. Compare
  3. vite-plugin-glsl vs vite-plugin-glslify
NPM Compare

Compare NPM packages statistics, trends, and features

CollectionsVS Code extensionChrome extensionTermsPrivacyLinkTreeIndiehackersBig Frontendqiuyumi

GLSL Integration for Vite: vite-plugin-glsl vs vite-plugin-glslify

Both vite-plugin-glsl and vite-plugin-glslify help integrate GLSL (OpenGL Shading Language) into Vite projects. They enable developers to write shaders in GLSL and use them in their applications. This comparison helps you choose the best package for your project. While they share a similar goal, they have different approaches and features.

Development ToolsViteGLSLShaderBuild Tool

Unable to load comparison data. Please try again later.

Similar Packages

rollup-plugin-glsl

80%

A Rollup plugin that allows you to import GLSL shaders as ES modules. It compiles GLSL code into JavaScript modules that can be imported and used in your application.

If you're already using Rollup as your bundler, this plugin is a great alternative to vite-plugin-glsl. It provides similar functionality, but is specifically designed for Rollup. It's also well-maintained and has a strong community behind it.

Build Tools

webpack-glsl-loader

80%

A Webpack loader that allows you to import GLSL shaders as modules. It compiles GLSL code into JavaScript modules that can be imported and used in your application.

If you're using Webpack as your bundler, this loader is a great alternative to vite-plugin-glsl. It provides similar functionality, but is specifically designed for Webpack. It's also well-maintained and has a strong community behind it.

Build Tools

glslify

70%

A browserify transform that allows you to import GLSL shaders as modules. It compiles GLSL code into JavaScript modules that can be imported and used in your application.

If you're using Browserify as your bundler, this transform is a great alternative to vite-plugin-glslify. It provides similar functionality, but is specifically designed for Browserify. It's also well-maintained and has a strong community behind it.

Build Tools

Vite Plugin GLSL

Import, inline (and minify) GLSL/WGSL shader files

npm GitHub package.json version GitHub

Inspired by threejs-glsl-loader and vite-plugin-string, compatible with Babylon.js, three.js and lygia.

Installation

npm i vite-plugin-glsl --save-dev # or yarn add vite-plugin-glsl --dev # or pnpm add -D vite-plugin-glsl # or bun add vite-plugin-glsl --dev

Usage

// vite.config.js import glsl from 'vite-plugin-glsl'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [glsl()] });

With TypeScript

Add extension declarations to your types in tsconfig.json:

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

or as a package dependency directive to your global types:

/// <reference types="vite-plugin-glsl/ext" />

Default Options

glsl({ include: [ // Glob pattern, or array of glob patterns to import '**/*.glsl', '**/*.wgsl', '**/*.vert', '**/*.frag', '**/*.vs', '**/*.fs' ], exclude: undefined, // Glob pattern, or array of glob patterns to ignore defaultExtension: 'glsl', // Shader suffix to use when no extension is specified warnDuplicatedImports: true, // Warn if the same chunk was imported multiple times removeDuplicatedImports: false, // Automatically remove an already imported chunk importKeyword: '#include', // Keyword used to import shader chunks minify: false, // Minify/optimize output shader code watch: true, // Recompile shader on change root: '/' // Directory for root imports })

Example

root
├── src/
│   ├── glsl/
│   │   ├── chunk0.frag
│   │   ├── chunk3.frag
│   │   ├── main.frag
│   │   ├── main.vert
│   │   └── utils/
│   │       ├── chunk1.glsl
│   │       └── chunk2.frag
│   └── main.js
├── vite.config.js
└── package.json
// main.js import fragment from './glsl/main.frag';
// main.frag #version 300 es #ifndef GL_FRAGMENT_PRECISION_HIGH precision mediump float; #else precision highp float; #endif out vec4 fragColor; #include chunk0.frag; void main (void) { fragColor = chunkFn(); }
// chunk0.frag // ".glsl" extension will be added automatically: #include utils/chunk1; vec4 chunkFn () { return vec4(chunkRGB(), 1.0); }
// utils/chunk1.glsl #include chunk2.frag; #include ../chunk3.frag; vec3 chunkRGB () { return vec3(chunkRed(), chunkGreen(), 0.0); }
// utils/chunk2.frag float chunkRed () { return 0.0; }
// chunk3.frag float chunkGreen () { return 0.8; }

Will result in:

// main.frag #version 300 es #ifndef GL_FRAGMENT_PRECISION_HIGH precision mediump float; #else precision highp float; #endif out vec4 fragColor; float chunkRed () { return 0.0; } float chunkGreen () { return 0.8; } vec3 chunkRGB () { return vec3(chunkRed(), chunkGreen(), 0.0); } vec4 chunkFn () { return vec4(chunkRGB(), 1.0); } void main (void) { fragColor = chunkFn(); }

Change Log

  • Starting from v1.5.1 this plugin is fully compatible with vite^7.0.0.

  • Starting from v1.5.0 this plugin supports a custom importKeyword to include shader chunks.

  • Starting from v1.4.0 compress option was renamed to minify and now it allows a promise callback.

  • Starting from v1.3.2 this plugin allows to automatically remove already imported chunks with the removeDuplicatedImports option set to true.

  • Starting from v1.3.1 this plugin is fully compatible with vite^6.0.0.

  • Starting from v1.3.0 this plugin will not remove comments starting with ///, unless compress option is set to true.

  • Starting from v1.2.0 this plugin is fully compatible with vite^5.0.0.

  • Starting from v1.1.1 this plugin has a complete TypeScript support. Check "Usage" > "With TypeScript" for more info.

  • Starting from v1.0.0 this plugin is fully compatible with vite^4.0.0.

  • Starting from v0.5.4 this plugin supports custom compress callback function to optimize output shader length after all shader chunks have been included.

  • Starting from v0.5.0 this plugin supports shaders hot reloading when watch option is set to true.

  • Starting from v0.4.0 this plugin supports chunk imports from project root and root option to override the default root directory.

  • Starting from v0.3.0 this plugin is pure ESM. Consider updating your project to an ESM module by adding "type": "module" in your package.json or consult this issue for possible workarounds.

  • Starting from v0.2.2 this plugin supports compress option to optimize output shader length. You might consider setting this to true in production environment.

  • Starting from v0.2.0 this plugin uses a config object as a single argument to glsl function and allows to disable import warnings with the warnDuplicatedImports param set to false.

  • Starting from v0.1.5 this plugin warns about duplicated chunks imports and throws an error when a recursive loop occurres.

  • Starting from v0.1.2 this plugin generates sourcemaps using vite esbuild when the sourcemap option is set to true.

  • Starting from v0.1.0 this plugin supports WebGPU shaders with .wgsl extension.

  • Starting from v0.0.9 this plugin supports optional semicolons at the end of #include statements.

  • Starting from v0.0.7 this plugin supports optional single and double quotation marks around file names.

Note:

When used with three.js r0.99 and higher, it's possible to include shader chunks as specified in the documentation, those imports will be ignored by vite-plugin-glsl since they are handled internally by the library itself:

#include <common> vec3 randVec3 (const in vec2 uv) { return vec3( rand(uv * 0.1), rand(uv * 2.5), rand(uv) ); }

vite-plugin-glslify

A plugin for Vite to compile glslify shader code

Usage

Install

$ yarn add --D vite-plugin-glslify # or npm i -D vite-plugin-glslify

Add it to vite.config.*

// vite.config.js import { glslify } from 'vite-plugin-glslify' export default { plugins: [ glslify() ], }

That's it, now it will compile your glslify shader code.

It will transpile glsl`...` or glsl(`...`).

Other details, see glslify.

Example

const frag = glsl` #pragma glslify: ease = require('glsl-easings/sine-in') precision mediump float; varying vec3 vpos; void main () { gl_FragColor = vec4(ease(vpos*25.0),1); } `

Will be transpiled to

const frag = ` #ifndef HALF_PI #define HALF_PI 1.5707963267948966 #endif float sineIn(float t) { return sin((t - 1.0) * HALF_PI) + 1.0; } precision mediump float; varying vec3 vpos; void main () { gl_FragColor = vec4(ease(vpos*25.0),1); } `

Or you can import files with extensions like *.glsl, *.vert, *.frag, see example.

Interfaces

/** * A valid `minimatch` pattern, or array of patterns. */ export type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null; import { Plugin } from 'vite'; import { FilterPattern } from '@rollup/pluginutils'; declare type GlslifyTransform<Options = any> = (filename: string, src: string, options: Options, done: (error: any, src: string) => void) => string; interface GlslifyOptions { transforms?: (GlslifyTransform | string | [ GlslifyTransform | string, any ])[]; } interface Options { /** * included files or folder, defaults to [/\.ts$/, /\.js$/] */ include?: FilterPattern; /** * excluded files or folder, defaults to ['node_modules/**'] */ exclude?: FilterPattern; /** * should transform literals with literalsCompiler, defaults to true */ transformLiterals?: boolean; /** * function calling that should be compiled, defaults to [/glsl/] */ funcName?: FilterPattern; /** * should transform files with filesCompiler, defaults to true */ transformFiles?: boolean; /** * extensions of files that should be compiled, defaults to [/\.vert$/, /\.frag$/, /\.glsl$/] */ extensions?: FilterPattern; /** * options passed to glslify */ options?: GlslifyOptions; } declare const DEFAULT_EXTENSIONS: RegExp[]; declare function glslify(options?: Options): Plugin[]; export { DEFAULT_EXTENSIONS, glslify as default, glslify };

LICENSE

MIT

Dependencies Comparison

vite-plugin-glsl

Dependencies

@rollup/pluginutils^5.1.4

Dev Dependencies

vite^6.3.5

Peer Dependencies

vite>= 3.x

vite-plugin-glslify

Dependencies

@rollup/pluginutils^4.1.1
astring^1.7.5
estree-walker^2.0.2
glslify^7.1.1
magic-string^0.25.7

Dev Dependencies

@kuss/eslint-config-vanilla^2.6.1
@release-it/conventional-changelog^5.1.1
eslint^8.44.0
release-it^15.11.0
tsup^7.1.0
typescript^5.1.6
vite^5.2.9

Peer Dependencies

vite^5.2.9 || ^6
StarsIssuesVersionUpdatedⓘLast publish dateCreatedⓘPackage creation dateSizeⓘMinified + Gzipped size
V
vite-plugin-glsl
38211.5.13 months ago4 years agoinstall size 9.5 KB
V
vite-plugin-glslify
00N/AN/AN/Ainstall size N/A

Who's Using These Packages

vite-plugin-glsl

infinite-world
infinite-world

Infinite procedurally generated world generated in WebGL with Three.js

pentool
pentool

Vector graphics editor with programmable pen tools

portfolio
portfolio

My portfolio website build with Nuxt, Scss and GSAP

modern-three
modern-three

Modern ThreeJS boilerplate powered by Vite & Typescript.

aladin-lite
aladin-lite

An astronomical HiPS visualizer in the browser

vite-plugin-glslify

drei
drei

🥉 useful helpers for react-three-fiber

audius-protocol
audius-protocol

The Audius Protocol - Freedom to share, monetize, and listen to any audio content.

dxos
dxos

TypeScript implementation of the DXOS protocols, SDK, toolchain and Composer.

Pocket-Saber
Pocket-Saber

Pocket Saber (WebRTC)

Floema-Vite
Floema-Vite