typescript-glslminify-transformer
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

typescript-glslminify-transformer

minify glsl code in typescript string literal

Install

npm i -D typescript-glslminify-transformer ts-patch

Usage

add following to tsconfig.json

{
    "compilerOptions": {
        "plugins": [ { "transform": "typescript-glslminify-transformer" } ]
    }
}

then use tspc to compile

tspc

Example

every string literal with /* glsl */ comment will be minified

const glslString = /* glsl */ "gl_FragColor = vec4(vUv, 0.0, 1.0);";

const glslTemplateString = /* glsl */ `
    #define PI 3.141592653589793
    precision mediump float;
    varying vec2 vUv;
    void main () {
        #ifdef SOME_DEFINE
        someFunction();
        #endif
        gl_FragColor = vec4(vUv, 0.0, 1.0);
    }
`;

const glslTemplateStringWithPlaceholders = /* glsl */`
    precision mediump float;
    varying vec2 vUv;
    void main () {
        #ifdef ${"SOME" + "_DEFINE"}
        someFunction();
        #endif
        gl_FragColor = vec4(vUv, ${1}, ${2});
    }
`;

will be transformed to

const glslString = /* glsl */ "gl_FragColor=vec4(vUv,0.0,1.0);";
const glslTemplateString = /* glsl */ "#define PI 3.141592653589793\nprecision mediump float;varying vec2 vUv;void main () {\n#ifdef SOME_DEFINE\nsomeFunction();\n#endif\ngl_FragColor=vec4(vUv,0.0,1.0);}\n";
const glslTemplateStringWithPlaceholders = /* glsl */ `precision mediump float;varying vec2 vUv;void main () {\n#ifdef \n${"SOME" + "_DEFINE"}someFunction();\n#endif\ngl_FragColor=vec4(vUv,${1},${2});}\n`;

Package Sidebar

Install

npm i typescript-glslminify-transformer

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

9.29 kB

Total Files

5

Last publish

Collaborators

  • noname0310