Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: browserslist config file support #9499

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/babel-preset-app/src/index.js
Expand Up @@ -56,6 +56,17 @@ function getPolyfills (targets, includes, { ignoreBrowserslistConfig, configPath
))
}

function getTargetsFromBrowserslistRc (browserslistEnv = 'client') {
const { default: getTargets } = require('@babel/helper-compilation-targets')
const targets = getTargets(undefined, { browserslistEnv })

if (Object.keys(targets).length !== 0) {
return targets
} else {
return undefined
}
}

module.exports = (api, options = {}) => {
const presets = []
const plugins = []
Expand All @@ -70,7 +81,7 @@ module.exports = (api, options = {}) => {
useBuiltIns = 'usage',
modules = false,
spec,
ignoreBrowserslistConfig = envName === 'modern',
ignoreBrowserslistConfig,
configPath,
include,
exclude,
Expand All @@ -97,6 +108,10 @@ module.exports = (api, options = {}) => {
modern: { esmodules: true }
}

if (envName !== 'server' && !options.targets) {
options.targets = getTargetsFromBrowserslistRc(envName)
}

const { targets = defaultTargets[envName] } = options

const polyfills = []
Expand Down