Skip to content

Commit

Permalink
feat: browserlist config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-fadaei committed Jun 30, 2021
1 parent eb6bd9f commit 3db2df9
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 3db2df9

Please sign in to comment.