Skip to content

Commit d0fd27a

Browse files
committed
merge buble/templateBuble options
1 parent 826f444 commit d0fd27a

File tree

3 files changed

+35
-44
lines changed

3 files changed

+35
-44
lines changed

docs/en/features/es2015.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ We are using ES2015's Object literal shorthand here to define the child componen
2626

2727
### ES2015 in Templates
2828

29-
Note that expressions inside `<template>`s do not get processed by the same Babel (or Buble) configuration like the `<script>` parts, because some ES2015 features cannot be compiled into render-function-friendly code. However, `vue-loader` does process the generated render function to selectively support a few convenient ES2015 features:
30-
31-
- [Template string interpolation](http://es6-features.org/#StringInterpolation)
32-
- [Object property shorthand](http://es6-features.org/#PropertyShorthand)
33-
- [Object method shorthand](http://es6-features.org/#MethodProperties)
34-
- [Computed property names](http://es6-features.org/#ComputedPropertyNames)
35-
36-
These features are quite convenient in dynamic class bindings, for example:
29+
`<template>` in `*.vue` files are compiled into JavaScript render functions and then processed by a custom build of [Buble](https://buble.surge.sh/guide/) to support ES2015 features. This allows you to use features such as [Object shorthand properties](https://buble.surge.sh/guide/#object-shorthand-methods-and-properties-transforms-concisemethodproperty-) and [computed properties](https://buble.surge.sh/guide/#computed-properties-transforms-computedproperty-):
3730

3831
``` html
3932
<div :class="[{ active: active }, isButton ? prefix + '-button' : null]">
@@ -45,7 +38,23 @@ can be simplified to:
4538
<div :class="{ active, [`${prefix}-button`]: isButton }">
4639
```
4740

48-
You can also customize the features supported in tempaltes using the [`templateBuble` option](../options.md#templatebuble).
41+
**vue@^2.1.0 only:** You can even use parameter destructuring with `v-for` or scoped slots:
42+
43+
``` html
44+
<li v-for="{ id, text } in items">
45+
{{ id }} {{ text }}
46+
</li>
47+
```
48+
49+
``` html
50+
<my-component>
51+
<template scope="{ id, text }">
52+
<span>{{ id }} {{ text }}</span>
53+
</template>
54+
</my-component>
55+
```
56+
57+
You can also customize the features supported in tempaltes using the [`buble` option](../options.md#buble).
4958

5059
### Transpiling Normal `.js` Files
5160

docs/en/options.md

+16-34
Original file line numberDiff line numberDiff line change
@@ -117,54 +117,36 @@ module.exports = {
117117
- type: `Object`
118118
- default: `{}`
119119

120-
Configure options for `buble-loader` (if present). For example, to enable Object spread operator:
120+
Configure options for `buble-loader` (if present), AND the buble compilation pass for template render functions.
121+
122+
The template render functions compilation supports a special transform `stripWith` (enabled by default), which removes the `with` usage in generated render functions to make them strict-mode compliant.
123+
124+
Example configuration:
121125

122126
``` js
127+
// webpack 1
123128
vue: {
124129
buble: {
125-
objectAssign: 'Object.assign'
126-
}
127-
}
128-
```
129-
130-
### templateBuble
130+
// enable object spread operator
131+
// NOTE: you need to provide Object.assign polyfill yourself!
132+
objectAssign: 'Object.assign',
131133

132-
- type: `Object`
133-
- default:
134-
``` js
135-
{
136-
target: { chrome: 52 },
137-
transforms: {
138-
stripWith: true, // vue only
139-
computedProperty: true,
140-
conciseMethodProperty: true,
141-
templateString: true
134+
// turn off the `with` removal
135+
transforms: {
136+
stripWith: false
137+
}
142138
}
143139
}
144-
```
145-
146-
Configure options for a [Buble](https://buble.surge.sh/) transpile pass applied to raw render functions. The purpose of this additional pass is to:
147-
148-
1. add selective support to a few ES2015 features that are handy in template expressions (whitelisted in default transforms);
149140

150-
2. remove the `with` block inside render functions to make it strict-mode compliant and a bit more performant. This is enabled by the custom `stripWith` transform, and applied only at build time so that the base template compiler can be extremely small and lightweight.
151-
152-
With this option you can turn on additional [transforms](https://buble.surge.sh/guide/#supported-features) (e.g. arrow functions) or turn off `with` removal based on your specific needs. Example config with Webpack 2:
153-
154-
``` js
141+
// webpack 2
155142
module: {
156143
rules: [
157144
{
158145
test: /\.vue$/,
159146
loader: 'vue',
160147
options: {
161-
templateBuble: {
162-
objectAssign: 'Object.assign',
163-
// transforms object is merged with the defaults
164-
transforms: {
165-
stripWith: false,
166-
arrow: true
167-
}
148+
buble: {
149+
// same options
168150
}
169151
}
170152
}

lib/template-compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = function (html) {
7171
code = transpile('module.exports={' +
7272
'render:' + toFunction(compiled.render) + ',' +
7373
'staticRenderFns: [' + compiled.staticRenderFns.map(toFunction).join(',') + ']' +
74-
'}', vueOptions.templateBuble)
74+
'}', vueOptions.buble)
7575
}
7676
// hot-reload
7777
if (!isServer &&

0 commit comments

Comments
 (0)