A browserify transform (and standalone function)
const values into your code. Like
envify, this comes in handy for things
such as conditional compilation and as such works well with
constantify will pick up
const definitions at the top of your module, i.e.
outside of any closures, and replace their references with their actual values.
Note that this only works with strings and numbers.
For example, the following code:
const generate =const SIZE = 64const SIZE_SQUARED = 64*64var array = SIZE_SQUAREDvar n = 0for var x = 0; x < SIZE; x += 1for var y = 0; y < SIZE; y += 1arrayn++ =
Will be transformed to become this:
const generate =var array = 4096var n = 0for var x = 0; x < 64; x += 1for var y = 0; y < 64; y += 1arrayn++ =
You can use constantify the same you would as any other browserify transform:
browserify -t constantify
And to use it from another module, just pass it your source as a string to the
fromString method, like so:
var constantify =var fs =var file = fsvar transformed = constantifyconsole
You can also use it as a standalone command-line tool if installed globally:
constantify index.js > bundled.jscat index.js | constantify > bundled.js
MIT. See LICENSE.md for details.