Skip to content

Commit

Permalink
fix(plugin-legacy): add default value of targets
Browse files Browse the repository at this point in the history
  • Loading branch information
KAROTT7 committed Jan 28, 2023
1 parent b49206b commit 55f605c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-legacy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ npm add -D terser
### `targets`

- **Type:** `string | string[] | { [key: string]: string }`
- **Default:** `undefined`
- **Default:** `'last 2 versions and not dead, > 0.3%, Firefox ESR'`

If explicitly set, it's passed on to [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#targets).

The query is also [Browserslist compatible](https://github.com/browserslist/browserslist). The value `'defaults'`, is what is recommended by Browserslist. See [Browserslist Best Practices](https://github.com/browserslist/browserslist#best-practices) for more details.
The query is also [Browserslist compatible](https://github.com/browserslist/browserslist). See [Browserslist Best Practices](https://github.com/browserslist/browserslist#best-practices) for more details.

### `polyfills`

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"@babel/core": "^7.20.5",
"@babel/preset-env": "^7.20.2",
"browserslist": "^4.21.4",
"core-js": "^3.26.1",
"magic-string": "^0.27.0",
"regenerator-runtime": "^0.13.11",
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
} from 'rollup'
import type { PluginItem as BabelPlugin } from '@babel/core'
import colors from 'picocolors'
import browserslist from 'browserslist'
import type { Options } from './types'

// lazy load babel since it's not used during dev
Expand Down Expand Up @@ -119,7 +120,10 @@ const _require = createRequire(import.meta.url)

function viteLegacyPlugin(options: Options = {}): Plugin[] {
let config: ResolvedConfig
const targets = options.targets
const targets =
browserslist() ||
options.targets ||
'last 2 versions and not dead, > 0.3%, Firefox ESR'
const genLegacy = options.renderLegacyChunks !== false
const genDynamicFallback = genLegacy

Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 55f605c

Please sign in to comment.