Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'babel-preset-env' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
async function getEnvPlugins(targets, useBuiltIns = false) {
if (!targets) {
return null;
}
let key = JSON.stringify(targets);
if (envCache.has(key)) {
return envCache.get(key);
}
let plugins = presetEnv.default(
{},
{targets, modules: false, useBuiltIns: useBuiltIns ? 'entry' : false}
).plugins;
// babel-preset-env version 6.x does not cover object-rest-spread so always
// add it.
plugins.push([
require('babel-plugin-transform-object-rest-spread'),
{useBuiltIns}
]);
envCache.set(key, plugins);
return plugins;
}
export default function loadBabelLibs () {
return {
babel: require('babel-core'),
presetStage2: require('babel-preset-stage-2'),
presetFlow: require('babel-preset-flow'),
transformClassProperties: require('babel-plugin-transform-class-properties'),
transformRuntime: require('babel-plugin-transform-runtime'),
transformForOfAsArray: require('babel-plugin-transform-for-of-as-array').default,
presetFallback: require('babel-preset-env').default(null, getOptsForPresetFallback()),
presetEnv: require('babel-preset-env').default(null, getOptsForPresetEnv())
};
}
export default function loadBabelLibs () {
return {
babel: require('babel-core'),
presetStage2: require('babel-preset-stage-2'),
presetFlow: require('babel-preset-flow'),
transformClassProperties: require('babel-plugin-transform-class-properties'),
transformRuntime: require('babel-plugin-transform-runtime'),
transformForOfAsArray: require('babel-plugin-transform-for-of-as-array').default,
presetFallback: require('babel-preset-env').default(null, getOptsForPresetFallback()),
presetEnv: require('babel-preset-env').default(null, getOptsForPresetEnv())
};
}
function transpile(src, dest) {
const sourcesHtmlSplitter = new polymer_build.HtmlSplitter();
return gulp.src(src)
.pipe(sourcesHtmlSplitter.split())
.pipe(gulpif(/\.js$/, babel({presets: [babel_preset_env.default()]})))
.pipe(sourcesHtmlSplitter.rejoin())
.pipe(gulp.dest(dest));
}
module.exports = function buildPreset () {
return {
presets: [
require('babel-preset-env').default(null, {
targets: {
browsers: ['last 2 versions', 'ie 11'],
node: '8.9.4',
},
modules: false,
}),
require('babel-preset-react'),
],
plugins: [
require('babel-plugin-transform-object-rest-spread'),
require('babel-plugin-transform-class-properties'),
require('babel-plugin-transform-export-extensions'),
],
};
};
JSHandler.prototype.getBabelPluginsHash = function () {
const babelOptions = this.getBabelEnvOptions(this.userAgent)
const functions = babelPresetEnv(null, babelOptions).plugins.map(plugin => plugin[0])
const hashSource = functions.reduce((result, functionSource) => {
if (typeof functionSource === 'function') {
return result + functionSource.toString()
} else if (typeof functionSource.default === 'function') {
return result + functionSource.default.toString()
}
return result
}, '')
const hash = farmhash.fingerprint64(hashSource)
return hash
}
const buildPreset = require('babel-preset-env').buildPreset
const BABEL_ENV = process.env.BABEL_ENV
module.exports = {
presets: [
[ buildPreset, {
loose: true,
modules: BABEL_ENV === 'es' ? false : 'commonjs'
} ]
]
}