varify

browserify transform that converts all const assignments to var assignments.

varify

browserify transform that converts all const assignments to var assignments.

npm install varify

So you can get the benefits of immutable variables with help of lint tools while staying compatible with older browsers that have no const.

Given this JavaScript:

const a = 1;
 
var keep = { const: 1 };
keep.const = 2;
 
const foo = function () {
  console.log('some const s should be left unchanged');
};

Running browserify with varify transform:

require('browserify')
  .transform(require('varify'))
  .add(__dirname + '/sample.js')
  .bundle()
  .pipe(process.stdout);

Outputs:

var a = 1;
 
var keep = { const: 1 };
keep.const = 2;
 
var foo = function () {
  console.log('some const s should be left unchanged');
};
browserify -t varify sample.js > bundle.js