injectr icon indicating copy to clipboard operation
injectr copied to clipboard

Using injectr with babel

Open sheepsteak opened this issue 9 years ago • 1 comments

I have injectr.onload set up to run files through babel like so:

injectr.onload = (file, content) => {
  return require('babel').transform(content, {
    filename: file,
    optional: ['runtime', 'es7.classProperties', 'es7.objectRestSpread']
  }).code;
};

This works but it seems like the polyfilled methods such as [1, 2, 3].includes(2) have to be written as Array.includes([1, 2, 3], 2) instead. Even if I prepend the file content with require('babel/polyfill') I get the same result.

Do you know why the polyfilled methods wouldn't be usable with an injected module?

sheepsteak avatar Jun 23 '15 10:06 sheepsteak

@sheepsteak it might be possible if the babel/polyfill is applied to the module calling injectr(..) and that passes in the current global as the context e.g.

const someModule = injectr('./some-module.js', {}, global);

sonewman avatar Jul 26 '15 10:07 sonewman