You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- using `browserslist` field in `package.json` when building for browsers
14
13
- set to `{ node: 'current' }` when running unit tests in Node.js
15
-
- Includes `Promise`and `Object.assign` polyfills by default so that they are usable even in non-transpiled dependencies (only for environments that need them)
14
+
- Includes `Promise`polyfill by default so that they are usable even in non-transpiled dependencies (only for environments that need it)
@@ -26,50 +25,57 @@ This is the default Babel preset used in all Vue CLI projects.
26
25
27
26
## Options
28
27
29
-
-**modules**
28
+
### modules
30
29
31
-
Default:
30
+
- Default:
32
31
-`false` when building with webpack
33
32
-`'commonjs'` when running tests in Jest.
34
33
35
-
Explicitly set `modules` option for `babel-preset-env`. See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#modules) for more details.
34
+
Explicitly set `modules` option for `babel-preset-env`. See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#modules) for more details.
36
35
37
-
-**targets**
36
+
### targets
38
37
39
-
Default:
38
+
- Default:
40
39
- determined from `browserslist` field in `package.json` when building for browsers
41
40
- set to `{ node: 'current' }` when running unit tests in Node.js
42
41
43
-
Explicitly set `targets` option for `babel-preset-env`. See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#targets) for more details.
42
+
Explicitly set `targets` option for `babel-preset-env`. See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#targets) for more details.
44
43
45
-
-**useBuiltIns**
44
+
### useBuiltIns
46
45
47
-
Default: `'usage'`
46
+
- Default: `'usage'`
47
+
- Allowed values: `'usage' | 'entry' | false`
48
48
49
-
Explicitly set `useBuiltIns` option for `babel-preset-env`.
49
+
Explicitly set `useBuiltIns` option for `babel-preset-env`.
50
50
51
-
The default value is `'usage'`, which adds imports to polyfills based on the usage in transpiled code. Note that the usage detection does not apply to your dependencies (which are excluded by `cli-plugin-babel` by default). If one of your dependencies need polyfills, you have three options:
51
+
The default value is `'usage'`, which adds imports to polyfills based on the usage in transpiled code. For example, if you use `Object.assign` in your code, the corresponding polyfill will be auto-imported if your target environment does not supports it.
52
52
53
-
1. Add that dependency to the `transpileDependencies` option in `vue.config.js`. This would enable the same usage-based polyfill detection for that dependency as well;
53
+
Note that the usage detection does not apply to your dependencies (which are excluded by `cli-plugin-babel` by default). If one of your dependencies need polyfills, you have a few options:
54
54
55
-
2. OR, you can explicitly include the needed polyfills using the [polyfills](#polyfills) option for this preset.
55
+
1.**If the dependency is written in an ES version that your target environments do not support:** Add that dependency to the `transpileDependencies` option in `vue.config.js`. This would enable both syntax transforms and usage-based polyfill detection for that dependency.
56
56
57
-
3. Use `useBuiltIns: 'entry'` and then add `import '@babel/polyfill'` to your entry file. This will import **ALL** polyfills based on your `browserslist` targets so that you don't need to worry about dependency polyfills anymore, but will likely bloat your final bundle with some unused polyfills.
57
+
2.**If the dependency ships ES5 code and explicitly lists the polyfills needed:**you can pre-include the needed polyfills using the [polyfills](#polyfills) option for this preset.
58
58
59
-
See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#usebuiltins) for more details.
59
+
3.**If the dependency ships ES5 code, but uses ES6+ features without explicitly listing polyfill requirements (e.g. Vuetify):** Use `useBuiltIns: 'entry'` and then add `import '@babel/polyfill'` to your entry file. This will import **ALL** polyfills based on your `browserslist` targets so that you don't need to worry about dependency polyfills anymore, but will likely increase your final bundle size with some unused polyfills.
60
60
61
-
-**polyfills**
61
+
See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#usebuiltins) for more details.
62
62
63
-
Default: `['es6.promise', 'es6.object.assign']`
63
+
### polyfills
64
64
65
-
A list of [core-js](https://github.com/zloirock/core-js) polyfills to force-include when using `useBuiltIns: 'usage'`.
65
+
- Default: `['es6.promise']`
66
66
67
-
Use this option when you have 3rd party dependencies that are not processed by Babel but have specific polyfill requirements. **These polyfills are automatically excluded if they are not needed for your target environments specified via `browserslist`**.
67
+
A list of [core-js](https://github.com/zloirock/core-js) polyfills to pre-include when using `useBuiltIns: 'usage'`. **These polyfills are automatically excluded if they are not needed for your target environments**.
68
68
69
-
-**jsx**
69
+
Use this option when you have 3rd party dependencies that are not processed by Babel but have specific polyfill requirements (e.g. Axios and Vuex require Promise support).
70
70
71
-
Default: `true`. Set to `false` to disable JSX support.
71
+
### jsx
72
72
73
-
-**loose**
73
+
-Default: `true`.
74
74
75
-
Default: `false`. Setting this to `true` will generate code that is more performant but less spec-compliant.
75
+
Set to `false` to disable JSX support.
76
+
77
+
### loose
78
+
79
+
- Default: `false`.
80
+
81
+
Setting this to `true` will generate code that is more performant but less spec-compliant.
0 commit comments