babel-plugin-remove-glsl-comments

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

Babel plugin that removes GLSL comments (single-line // and block /* */) from shader source strings at build time. Current stable version: 1.0.0. Infrequently updated. Differentiators: designed specifically for GLSL within JavaScript, integrates with Babel pipeline, avoids runtime comment stripping. Alternative to manual regex or build-step scripts.

error Error: Cannot find module 'babel-plugin-remove-glsl-comments'
cause Package not installed or misspelled in config.
fix
Run 'npm install babel-plugin-remove-glsl-comments --save-dev' and verify package.json.
error TypeError: (intermediate value) is not a function
cause Using require() without .default in CommonJS.
fix
Replace 'const plugin = require('babel-plugin-remove-glsl-comments')' with 'const plugin = require('babel-plugin-remove-glsl-comments').default'.
error Error: Babel plugin 'remove-glsl-comments' specified in "plugins" but not found.
cause Incorrect plugin specifier in Babel config.
fix
Ensure the package is installed and use the full module path: 'module:remove-glsl-comments' or the shorthand 'remove-glsl-comments'.
breaking Plugin is not designed to handle complex GLSL preprocessor directives or nested comments (GLSL spec does not allow nested blocks).
fix Ensure GLSL code does not contain nested block comments; remove them manually.
deprecated Package may be deprecated in favor of using @luma.gl/shadertools or inline build tool plugins.
fix Consider migrating to luma.gl's shader module system if using WebGL.
gotcha Plugin only removes comments from GLSL strings, not from arbitrary JavaScript code. It must be applied to files containing GLSL template literals.
fix Ensure the plugin is included in the Babel config for files that contain GLSL strings.
npm install babel-plugin-remove-glsl-comments
yarn add babel-plugin-remove-glsl-comments
pnpm add babel-plugin-remove-glsl-comments

Shows how to configure the Babel plugin in babel.config.js and the expected transformation on a GLSL string.

// babel.config.js
module.exports = {
  plugins: [
    ['module:remove-glsl-comments', { /* options */ }],
  ],
};

// sample.js (transformed)
const vertexShader = `
  // vertex shader
  attribute vec3 position; // position attribute
  void main() {
    gl_Position = vec4(position, 1.0);
  }
`;
// After plugin: comments removed, GLSL preserved