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
Copy file name to clipboardExpand all lines: src/guide/web-components.md
+14-7Lines changed: 14 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -165,21 +165,28 @@ The [Provide / Inject API](/guide/component-provide-inject.html#provide-inject)
165
165
166
166
### SFC as Custom Element
167
167
168
-
The official build toolchains have built-in support for importing Vue Single File Components (SFCs) as custom elements. By default, files ending in `*.ce.vue` will be processed as native custom elements when imported (created with `defineCustomElement`):
168
+
`defineCustomElement` also works with Vue Single File Components (SFCs). However, with the default tooling setup, the `<style>` inside the SFCs will still be extracted and merged into a single CSS file during production build. When using an SFC as a custom element, it is often desirable to inject the `<style>` tags into the custom element's shadow root instead.
169
+
170
+
The official SFC toolings support importing SFCs in "custom element mode" (requires `@vitejs/plugin-vue@^1.4.0` or `vue-loader@^16.5.0`). An SFC loaded in custom element mode inlines its `<style>` tags as strings of CSS and exposes them under the component's `styles` option. This will be picked up by `defineCustomElement` and injected into the element's shadow root when instantiated.
171
+
172
+
To opt-in to this mode, simply end your component file name with `.ce.vue`:
When imported as custom elements, `<style>` inside the SFC will be inlined as JavaScript strings and inserted as a native `<style>` tag inside the custom element's shadow root.
181
187
182
-
If you wish to customize what files should be imported as custom elements (for example treating _all_ SFCs as custom elements), you can pass the `customElement` option to the respective build plugins:
188
+
189
+
If you wish to customize what files should be imported in custom element mode (for example treating _all_ SFCs as custom elements), you can pass the `customElement` option to the respective build plugins:
0 commit comments