Skip to content

Commit 445e1fa

Browse files
committed
feat: document 3.1 compilerOptions
1 parent 4aaa843 commit 445e1fa

File tree

2 files changed

+118
-44
lines changed

2 files changed

+118
-44
lines changed

src/api/application-config.md

Lines changed: 90 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,6 @@ const app = createApp({})
7777
app.config.globalProperties.$http = () => {}
7878
```
7979

80-
## isCustomElement
81-
82-
- **Type:** `(tag: string) => boolean`
83-
84-
- **Default:** `undefined`
85-
86-
- **Usage:**
87-
88-
```js
89-
// any element starting with 'ion-' will be recognized as a custom one
90-
app.config.isCustomElement = tag => tag.startsWith('ion-')
91-
```
92-
93-
Specifies a method to recognize custom elements defined outside of Vue (e.g., using the Web Components APIs). If component matches this condition, it won't need local or global registration and Vue won't throw a warning about an `Unknown custom element`.
94-
95-
> Note that all native HTML and SVG tags don't need to be matched in this function - Vue parser performs this check automatically
96-
97-
::: tip Important
98-
This config option is only respected when using the runtime compiler. If you are using the runtime-only build, `isCustomElement` must be passed to `@vue/compiler-dom` in the build setup instead - for example, via the [`compilerOptions` option in vue-loader](https://vue-loader.vuejs.org/options.html#compileroptions).
99-
:::
100-
10180
## optionMergeStrategies
10281

10382
- **Type:** `{ [key: string]: Function }`
@@ -139,3 +118,93 @@ The merge strategy receives the value of that option defined on the parent and c
139118
- **Usage**:
140119

141120
Set this to `true` to enable component init, compile, render and patch performance tracing in the browser devtool performance/timeline panel. Only works in development mode and in browsers that support the [performance.mark](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) API.
121+
122+
## compilerOptions <Badge text="3.1+" />
123+
124+
- **Type:** `Object`
125+
126+
Configure runtime compiler options. Values set on this object will be passed to the in-browser template compiler and affects every component in the configured app. Note you can also override these options on a per-component basis using the [`compilerOptions` option](/api/options-misc.html#compileroptions).
127+
128+
::: tip Important
129+
This config option is only respected when using the full build (i.e. the standalone `vue.js` that can compile templates in the browser). If you are using the runtime-only build with a build setup, compiler options must be passed to `@vue/compiler-dom` via build tool configurations instead.
130+
131+
- For `vue-loader`: [pass via the `compilerOptions` loader option](https://vue-loader.vuejs.org/options.html#compileroptions). Also see [how to configure it in `vue-cli`](https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader).
132+
133+
- For `vite`: [pass via `@vitejs/plugin-vue` options](https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom).
134+
:::
135+
136+
### compilerOptions.isCustomElement
137+
138+
- **Type:** `(tag: string) => boolean`
139+
140+
- **Default:** `undefined`
141+
142+
- **Usage:**
143+
144+
```js
145+
// any element starting with 'ion-' will be recognized as a custom one
146+
app.config.compilerOptions.isCustomElement = tag => tag.startsWith('ion-')
147+
```
148+
149+
Specifies a method to recognize custom elements defined outside of Vue (e.g., using the Web Components APIs). If component matches this condition, it won't need local or global registration and Vue won't throw a warning about an `Unknown custom element`.
150+
151+
> Note that all native HTML and SVG tags don't need to be matched in this function - Vue parser performs this check automatically.
152+
153+
### compilerOptions.whitespace
154+
155+
- **Type:** `'condense' | 'preserve'`
156+
157+
- **Default:** `'condense'`
158+
159+
- **Usage:**
160+
161+
```js
162+
app.config.compilerOptions.whitespace = 'preserve'
163+
```
164+
165+
By default, Vue removes/condenses whitespaces between template elements to produce more efficient compiled output:
166+
167+
1. Leading / ending whitespaces inside an element are condensed into a single space
168+
2. Whitespaces between elements that contains newlines are removed
169+
3. Consecutive whitepsaces in text nodes are condensed into a single space
170+
171+
Setting the value to `'preserve'` will disalbe (2) and (3).
172+
173+
### compilerOptions.delimiters
174+
175+
- **Type:** `Array<string>`
176+
177+
- **Default:** `{{ "['\u007b\u007b', '\u007d\u007d']" }}`
178+
179+
- **Restrictions:** This option is only available in the full build, with in-browser template compilation.
180+
181+
- **Usage:**
182+
183+
```js
184+
// Delimiters changed to ES6 template string style
185+
app.config.compilerOptions.delimiters = ['${', '}']
186+
```
187+
188+
Sets the delimiters used for text interpolation within the template.
189+
190+
Typically this is used to avoid conflicting with server-side frameworks that also use mustache syntax.
191+
192+
### compilerOptions.comments
193+
194+
- **Type:** `boolean`
195+
196+
- **Default:** `false`
197+
198+
- **Usage:**
199+
200+
```js
201+
app.config.compilerOptions.comments = true
202+
```
203+
204+
By default, Vue will remove HTML comments inside templates in production. Setting this option to `true` will force Vue to preserve comments even in production. Comments are always preserved during development.
205+
206+
This options is typically used when Vue is used with other libraries that rely on HTML comments.
207+
208+
## isCustomElement <Badge text="deprecated" type="warning"/>
209+
210+
Deprecated in 3.1.0. Use [`compilerOptions.isCustomElement`](#compileroptions-iscustomelement) instead.

src/api/options-misc.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,6 @@
1010

1111
Another benefit of specifying a `name` option is debugging. Named components result in more helpful warning messages. Also, when inspecting an app in the [vue-devtools](https://github.com/vuejs/vue-devtools), unnamed components will show up as `<AnonymousComponent>`, which isn't very informative. By providing the `name` option, you will get a much more informative component tree.
1212

13-
## delimiters
14-
15-
- **Type:** `Array<string>`
16-
17-
- **Default:** `{{ "['\u007b\u007b', '\u007d\u007d']" }}`
18-
19-
- **Restrictions:** This option is only available in the full build, with in-browser template compilation.
20-
21-
- **Details:**
22-
23-
Sets the delimiters used for text interpolation within the template.
24-
25-
Typically this is used to avoid conflicting with server-side frameworks that also use mustache syntax.
26-
27-
- **Example:**
28-
29-
```js
30-
createApp({
31-
// Delimiters changed to ES6 template string style
32-
delimiters: ['${', '}']
33-
})
34-
```
35-
3613
## inheritAttrs
3714

3815
- **Type:** `boolean`
@@ -64,3 +41,31 @@
6441
```
6542

6643
- **See also:** [Disabling Attribute Inheritance](../guide/component-attrs.html#disabling-attribute-inheritance)
44+
45+
## compilerOptions <Badge text="3.1+" />
46+
47+
- **Type:** `Object`
48+
49+
- **Details:**
50+
51+
This is the component-level equivalent of the [app-level `compilerOptions` config](/api/application-config.html#compileroptions).
52+
53+
- **Usage:**
54+
55+
```js
56+
const Foo = {
57+
// ...
58+
compilerOptions: {
59+
delimiters: ['${', '}'],
60+
comments: true
61+
}
62+
}
63+
```
64+
65+
::: tip Important
66+
Similar to the app-level `compilerOptions` config, this option is only respected when using the full build with in-browser template compilation.
67+
:::
68+
69+
## delimiters <Badge text="deprecated" type="warning" />
70+
71+
Deprecated in 3.1.0. Use `compilerOptions.delimiters` instead.

0 commit comments

Comments
 (0)