injectr
injectr copied to clipboard
Using injectr with babel
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 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);