{"id":19086,"library":"babel-plugin-inline-webgl-constants","title":"babel-plugin-inline-webgl-constants","description":"A Babel plugin that replaces long WebGL constants (e.g., gl.TEXTURE_2D) with their corresponding numeric values at build time. Version 1.0.3 is stable, used primarily within the luma.gl ecosystem. It reduces bundle size and avoids runtime lookups, particularly useful for WebGL applications deployed in production. The plugin is lightweight, with no additional runtime dependencies, and integrates seamlessly into existing Babel configurations. It is differentiated by its specific focus on WebGL constants, whereas general constant inlining plugins are broader.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/visgl/luma.gl","tags":["javascript","babel-plugin","webgl","strip gl constants"],"install":[{"cmd":"npm install babel-plugin-inline-webgl-constants","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-inline-webgl-constants","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-inline-webgl-constants","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export; required as a Babel plugin string in .babelrc or babel.config.js.","wrong":"const inlineWebglConstants = require('babel-plugin-inline-webgl-constants');","symbol":"default","correct":"import inlineWebglConstants from 'babel-plugin-inline-webgl-constants';"},{"note":"Named export for the plugin function, available since v1.0.0.","wrong":null,"symbol":"INLINE_WEBGL_CONSTANTS","correct":"import { INLINE_WEBGL_CONSTANTS } from 'babel-plugin-inline-webgl-constants';"},{"note":"Named export for mapping object; TypeScript types include this interface.","wrong":"import WebGLConstants from 'babel-plugin-inline-webgl-constants';","symbol":"WebGLConstants","correct":"import { WebGLConstants } from 'babel-plugin-inline-webgl-constants';"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  plugins: [\n    ['babel-plugin-inline-webgl-constants', {\n      // Optional: exclude specific constants from inlining\n      exclude: ['gl.TEXTURE_CUBE_MAP']\n    }]\n  ]\n};\n\n// Input source.js\ngl.bindTexture(gl.TEXTURE_2D, texture);\n// Output after Babel\ngl.bindTexture(3553, texture);","lang":"javascript","description":"Shows configuring the plugin in babel.config.js and the transformation of a WebGL constant to its numeric value."},"warnings":[{"fix":"Use direct property access (gl.TEXTURE_2D) in source code.","message":"Plugin may break if constants are accessed dynamically (e.g., via gl['TEXTURE_2D'])","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider using a general purpose constant inliner or rely on bundler optimization.","message":"This plugin is primarily maintained for luma.gl v8 and below; newer projects may benefit from tree-shaking or other minification techniques.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Manually inline or reference numeric values for extension constants.","message":"Plugin does not handle constants from extensions like 'gl.getExtension('OES_texture_float')'.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to Babel 7 or use a different version of the plugin if available.","message":"Only works with Babel 7; Babel 6 users must upgrade or use alternative.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Rename WebGL context variable to 'gl' or adjust plugin configuration (if supported).","message":"Plugin may produce incorrect output if WebGL context is not named 'gl'.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install --save-dev babel-plugin-inline-webgl-constants","cause":"Plugin not installed as a dev dependency.","error":"Error: Module 'babel-plugin-inline-webgl-constants' not found"},{"fix":"Ensure gl context is properly created and the plugin is configured correctly; check for dynamic access patterns.","cause":"WebGL context not initialized correctly or plugin inlined constant incorrectly.","error":"Cannot read property 'TEXTURE_2D' of undefined"},{"fix":"Reorder plugins in .babelrc so that inline-webgl-constants runs before other transformations.","cause":"Babel configuration conflict with other plugins (e.g., preval).","error":"Unexpected token: expected ( after argument list (preval)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}