rollup-plugin-shader

convert GLSL files to ES6 modules

Usage no npm install needed!

<script type="module">
  import rollupPluginShader from 'https://cdn.skypack.dev/rollup-plugin-shader';
</script>

README

rollup-plugin-shader

Convert GLSL files to ES6 modules:

// shader-vertex.glsl
attribute vec3 position;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
void main(void) {
    gl_Position = uPMatrix * uMVMatrix * vec4(position, 1.0);
}
// import a glsl file
import vertex from './shader-vertex.glsl';
console.log( typeof vertex );   // string

Installation

npm install --save-dev rollup-plugin-shader

Usage

// rollup.config.js
import shader from 'rollup-plugin-shader';

export default {
    input: 'src/main.js',
    output: {
        file: 'dist/bundle.js',
        format: 'cjs'
    },
    plugins: [
        shader( {
            // All match files will be parsed by default,
            // but you can also specifically include/exclude files
            include: '**/*.glsl',   // default: [ '**/*.glsl', '**/*.vs', '**/*.fs' ]
            exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ],

            // specify whether to remove comments
            removeComments: true,   // default: true
        } )
    ]
};

License

MIT