Default Babel preset for Vue CLI projects providing comprehensive JavaScript/TypeScript transpilation and polyfill management
npx @tessl/cli install tessl/npm-vue--babel-preset-app@5.0.0@vue/babel-preset-app is the default Babel preset used exclusively in Vue CLI projects. It provides comprehensive JavaScript/TypeScript transpilation and polyfill management with smart defaults for browser compatibility, automatic feature detection, and environment-specific optimizations.
npm install @vue/babel-preset-app (typically installed as part of Vue CLI)// CommonJS
const preset = require('@vue/babel-preset-app');
// ES modules (if supported)
import preset from '@vue/babel-preset-app';// babel.config.js
module.exports = {
presets: [
'@vue/babel-preset-app'
]
};
// With options
module.exports = {
presets: [
['@vue/babel-preset-app', {
targets: { node: 'current' },
useBuiltIns: 'usage',
polyfills: ['es.promise', 'es.object.assign']
}]
]
};@vue/babel-preset-app is built around several key components:
The main preset export that returns Babel configuration based on context and options.
/**
* Main preset function that returns Babel configuration
* @param {Object} context - Babel context object (automatically provided by Babel)
* @param {PresetOptions} options - Configuration options
* @returns {BabelConfig} Babel configuration object with presets, plugins, and overrides
*/
function preset(context, options = {});
interface PresetOptions {
// @babel/preset-env options
targets?: string | string[] | { [key: string]: string };
modules?: 'amd' | 'umd' | 'systemjs' | 'commonjs' | 'cjs' | 'auto' | false;
useBuiltIns?: 'usage' | 'entry' | false;
loose?: boolean;
debug?: boolean;
spec?: boolean;
ignoreBrowserslistConfig?: boolean;
configPath?: string;
include?: string[];
exclude?: string[];
forceAllTransforms?: boolean;
shippedProposals?: boolean;
bugfixes?: boolean;
// Vue CLI specific options
polyfills?: string[];
jsx?: boolean | object;
entryFiles?: string[];
absoluteRuntime?: string | boolean;
version?: string;
decoratorsBeforeExport?: boolean;
decoratorsLegacy?: boolean;
}
interface BabelConfig {
sourceType: 'unambiguous';
overrides: Array<{
exclude?: RegExp[];
include?: RegExp[];
presets: Array<[any, object] | any>;
plugins: Array<[any, object] | any>;
}>;
}string | string[] | object// Examples
targets: { ie: 9, chrome: 58 }
targets: '> 1%, last 2 versions'
targets: { node: 'current' } // Automatically set in test environment'usage' | 'entry' | false'usage'// Usage-based polyfill injection (default)
useBuiltIns: 'usage'
// Manual polyfill entry
useBuiltIns: 'entry'
// No automatic polyfills
useBuiltIns: false'amd' | 'umd' | 'systemjs' | 'commonjs' | 'cjs' | 'auto' | falsefalse (preserve ES modules), 'commonjs' in Jest testsstring[]['es.array.iterator', 'es.promise', 'es.object.assign', 'es.promise.finally']useBuiltIns: 'usage'polyfills: [
'es.promise',
'es.object.assign',
'es.array.includes'
]boolean | objecttrue// Enable JSX (default)
jsx: true
// Disable JSX
jsx: false
// JSX with options (Vue 2)
jsx: {
injectH: false,
vModel: false
}
// JSX with options (Vue 3)
jsx: {
transformOn: true,
optimize: false
}string[][] (from VUE_CLI_ENTRY_FILES environment variable)entryFiles: [
'./src/main.js',
'./src/admin.js'
]string | boolean// Use absolute path (default)
absoluteRuntime: '/path/to/node_modules/@babel/runtime'
// Use relative paths
absoluteRuntime: falsebooleanfalsebooleantruestringThe preset responds to several environment variables for automatic configuration:
interface EnvironmentVariables {
VUE_CLI_BABEL_TARGET_NODE?: 'true'; // Set targets to { node: 'current' }
VUE_CLI_BABEL_TRANSPILE_MODULES?: 'true'; // Set modules to 'commonjs'
VUE_CLI_BUILD_TARGET?: 'app' | 'wc' | 'wc-async'; // Adjust targets for build type
VUE_CLI_MODERN_BUILD?: 'true'; // Use modern browser targets
VUE_CLI_ENTRY_FILES?: string; // JSON array of entry files
VUE_CLI_TEST?: 'true'; // Test mode flag
VUE_CLI_TRANSPILE_BABEL_RUNTIME?: 'true'; // Internal flag for @vue/cli-plugin-babel to transpile @babel/runtime
NODE_ENV?: 'test' | 'development' | 'production'; // Automatic test mode detection
}The preset returns a Babel configuration with specific overrides:
interface BabelConfigOutput {
sourceType: 'unambiguous';
overrides: [
{
// Main application code
exclude: [/@babel[/|\\\\]runtime/, /core-js/];
presets: Array<[any, object]>; // @babel/preset-env + Vue JSX presets
plugins: Array<[any, object]>; // Transform plugins + polyfill injection
},
{
// @babel/runtime transpilation
include: [/@babel[/|\\\\]runtime/];
presets: Array<[any, object]>; // @babel/preset-env only
}
];
}Basic Vue CLI Project:
// babel.config.js (automatically generated by Vue CLI)
module.exports = {
presets: [
'@vue/babel-preset-app'
]
};Custom Browser Targets:
module.exports = {
presets: [
['@vue/babel-preset-app', {
targets: {
browsers: ['> 1%', 'last 2 versions', 'not ie <= 8']
}
}]
]
};Library Mode (No Polyfills):
module.exports = {
presets: [
['@vue/babel-preset-app', {
useBuiltIns: false,
jsx: false
}]
]
};Node.js/Testing Configuration:
module.exports = {
presets: [
['@vue/babel-preset-app', {
targets: { node: 'current' },
modules: 'commonjs'
}]
]
};Multi-page Application:
module.exports = {
presets: [
['@vue/babel-preset-app', {
entryFiles: [
'./src/main.js',
'./src/admin.js',
'./src/mobile.js'
]
}]
]
};The preset includes validation for polyfill names:
// Will throw error if polyfill doesn't exist in core-js-compat
polyfills: ['invalid.polyfill'] // Error: Cannot find polyfill invalid.polyfillCommon error patterns:
interface DefaultPolyfills {
'es.array.iterator': string;
'es.promise': string;
'es.object.assign': string;
'es.promise.finally': string;
}
interface PolyfillPlugin {
name: 'vue-cli-inject-polyfills';
visitor: {
Program(path: any, state: { filename: string }): void;
};
}
interface TargetEnvironments {
browsers?: string | string[];
node?: string | 'current';
esmodules?: boolean;
chrome?: string;
firefox?: string;
safari?: string;
edge?: string;
ie?: string;
ios?: string;
android?: string;
electron?: string;
}