Skip to content

Commit da833d6

Browse files
committed
refactor(babel): use individual plugins instead of stage presets
BREAKING CHANGE: @vue/babel-preset-app no longer includes @babel/preset-stage-2. Now the only pre stage-3 proposals included are dynamic import, decorators and class properties. This is because Babel 7 will be removing stage presets altogether.
1 parent 50f818a commit da833d6

File tree

4 files changed

+524
-495
lines changed

4 files changed

+524
-495
lines changed

packages/@vue/babel-preset-app/README.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,40 @@
22

33
This is the default Babel preset used in all Vue CLI projects. **Note: this preset is meant to be used exclusively in projects created via Vue CLI and does not consider external use cases.**
44

5-
## Included
6-
7-
- [@babel/preset-env](https://new.babeljs.io/docs/en/next/babel-preset-env.html)
8-
- `modules: false`
9-
- auto set to `'commonjs'` in Jest tests
10-
- [`useBuiltIns: 'usage'`](#usebuiltins)
11-
- `targets` is determined:
12-
- using `browserslist` field in `package.json` when building for browsers
13-
- set to `{ node: 'current' }` when running unit tests in Node.js
5+
## Included Features
6+
7+
### [@babel/preset-env](https://new.babeljs.io/docs/en/next/babel-preset-env.html)
8+
9+
`preset-env` automatically determines the transforms and polyfills to apply based on your browser target. See [Browser Compatibility](https://cli.vuejs.org/guide/browser-compatibility.html) section in docs for more details.
10+
11+
- `modules: false`
12+
- auto set to `'commonjs'` in Jest tests
13+
- [`useBuiltIns: 'usage'`](#usebuiltins)
14+
- `targets` is determined:
15+
- using `browserslist` field in `package.json` when building for browsers
16+
- set to `{ node: 'current' }` when running unit tests in Node.js
1417
- Includes `Promise` polyfill by default so that they are usable even in non-transpiled dependencies (only for environments that need it)
15-
- [@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime)
16-
- Only enabled for helpers since polyfills are handled by `babel-preset-env`
17-
- [dynamic import syntax](https://github.com/tc39/proposal-dynamic-import)
18-
- [Object rest spread](https://github.com/tc39/proposal-object-rest-spread)
19-
- [babel-preset-stage-2](https://github.com/babel/babel/tree/master/packages/babel-preset-stage-2)
20-
- Vue JSX support
21-
- [@babel/plugin-syntax-jsx](https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-jsx)
22-
- [babel-plugin-transform-vue-jsx](https://github.com/vuejs/babel-plugin-transform-vue-jsx)
23-
- ~~[babel-plugin-jsx-event-modifiers](https://github.com/nickmessing/babel-plugin-jsx-event-modifiers)~~ (temporarily disabled until fixed for Babel 7)
24-
- ~~[babel-plugin-jsx-v-model](https://github.com/nickmessing/babel-plugin-jsx-v-model)~~ (temporarily disabled until fixed for Babel 7)
18+
19+
### Stage 3 or Below
20+
21+
Only the following stage 3 or below features are supported (object reset spread is supported as part of `preset-env`):
22+
23+
- [Dynamic Import Syntax](https://github.com/tc39/proposal-dynamic-import)
24+
- [Proposal Class Properties](https://babeljs.io/docs/en/next/babel-plugin-proposal-class-properties.html)
25+
- [Proposal Decorators (legacy)](https://babeljs.io/docs/en/next/babel-plugin-proposal-decorators.html)
26+
27+
If you need additional stage 3 or below features, you need to install and configure it yourself.
28+
29+
### Vue JSX support
30+
31+
- [@babel/plugin-syntax-jsx](https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-jsx)
32+
- [babel-plugin-transform-vue-jsx](https://github.com/vuejs/babel-plugin-transform-vue-jsx)
33+
- ~~[babel-plugin-jsx-event-modifiers](https://github.com/nickmessing/babel-plugin-jsx-event-modifiers)~~ (temporarily disabled until fixed for Babel 7)
34+
- ~~[babel-plugin-jsx-v-model](https://github.com/nickmessing/babel-plugin-jsx-v-model)~~ (temporarily disabled until fixed for Babel 7)
35+
36+
### [@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime)
37+
38+
`transform-runtime` avoids inlining helpers in every file. This is enabled for helpers only, since polyfills are handled by `babel-preset-env`.
2539

2640
## Options
2741

packages/@vue/babel-preset-app/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ module.exports = (context, options = {}) => {
121121
// pass options along to babel-preset-env
122122
presets.push([require('@babel/preset-env'), envOptions])
123123

124-
// stage 2. This includes some important transforms, e.g. dynamic import
125-
// and rest object spread.
126-
presets.push([require('@babel/preset-stage-2'), {
127-
loose,
128-
useBuiltIns: useBuiltIns !== false,
129-
decoratorsLegacy: decoratorsLegacy !== false
130-
}])
124+
// additional <= stage-3 plugins
125+
// Babel 7 is removing stgage presets altogether because people are using
126+
// too much unstable proposals. Let's be conservative in the defaults here.
127+
plugins.push(
128+
require('@babel/plugin-syntax-dynamic-import'),
129+
[require('@babel/plugin-proposal-decorators'), { legacy: decoratorsLegacy !== false }],
130+
[require('@babel/plugin-proposal-class-properties'), { loose }],
131+
)
131132

132133
// transform runtime, but only for helpers
133134
plugins.push([require('@babel/plugin-transform-runtime'), {

packages/@vue/babel-preset-app/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
"dependencies": {
2424
"@babel/plugin-syntax-jsx": "7.0.0-beta.47",
2525
"@babel/plugin-transform-runtime": "7.0.0-beta.47",
26+
"@babel/plugin-proposal-decorators": "7.0.0-beta.47",
27+
"@babel/plugin-syntax-dynamic-import": "7.0.0-beta.47",
28+
"@babel/plugin-proposal-class-properties": "7.0.0-beta.47",
2629
"@babel/preset-env": "7.0.0-beta.47",
27-
"@babel/preset-stage-2": "7.0.0-beta.47",
2830
"@babel/runtime": "7.0.0-beta.47",
2931
"babel-helper-vue-jsx-merge-props": "^2.0.3",
3032
"babel-plugin-dynamic-import-node": "^2.0.0",

0 commit comments

Comments
 (0)