0.3.0 • Published 9 months ago

spglsl v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

spglsl - a webgl glsl minifier based on Google Angle

Execuce preprocessor directives, removes whitespaces, applies constant folding, mangle non exported functions and variable names. Used in https://github.com/SalvatorePreviti/js13k-2020

Installation

Package is precompiled at https://www.npmjs.com/package/spglsl

npm i spglsl --save

Usage

import { spglslAngleCompile } from "spglsl";

async function compileFile() {
  const result = await spglslAngleCompile({
    mainFilePath: "myfile.frag",
    mainSourceCode: fs.readFileSync("myfile.frag", "utf8"),

    minify: true,

    // Mangle everything, except uniforms and globals, "main" and function starting with "main"
    mangle: true,

    // Map of global variables to rename
    mangle_global_map: {
      my_uniform_to_rename: "x",
      my_fragment_input_to_rename: "y",
    },
  });

  if (!result.valid) {
    console.log(result.infoLog);
    throw new Error("compilation failed");
  }

  // Prints all the uniform used, key is the original uniform name and value is the renamed uniform, if it was defined in mangle_global_map
  console.log(result.uniforms);

  // Prints all the globals used, key is the original variable name and value is the renamed uniform, if it was defined in mangle_global_map
  // Globals are varying, vertex and fragment input, outputs and buffers ...
  // Globals do not include uniforms.
  console.log(result.globals);

  return result.output;
}

There is also an handy rollup and vite plugin:

import { rollupPluginSpglsl } from "spglsl";

const pluginToPassToRollupOrVite = rollupPluginSpglsl({ ...options });

License

MIT license Salvatore Previti Copyright 2020-2022

Angle Copyright 2018 The ANGLE Project Authors.

Development

The project is mostly C++, compiled to WASM with Emscripten and runnable in NodeJS. Look at project/scripts folder on how to install dependencies and build.

0.3.0

9 months ago

0.2.8

1 year ago

0.2.7

2 years ago

0.0.21

3 years ago

0.1.0

3 years ago

0.2.1

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.2.6

3 years ago

0.2.3

3 years ago

0.1.4

3 years ago

0.2.2

3 years ago

0.1.3

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.1.5

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.9

4 years ago

0.0.16

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.3

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.6

4 years ago

0.0.2

4 years ago

0.0.1-alpha4

5 years ago

0.0.1-alpha3

5 years ago

0.0.1-alpha2

5 years ago

0.0.1-alpha1

5 years ago