swDefinePublic()
WARNING
Single File Component (SFC) support for Administration extensions is experimental. It is available since Shopware 6.7.16.0. The APIs described on this page can still change without a deprecation. Try it out and tell us what you find, but do not ship an extension built on it to customers or to the Shopware Store until the API is declared stable (planned for 6.9).
function swDefinePublic<T extends Record<PropertyKey, unknown>>(bindings: T): void;Base components only. Declares which of the file's top-level bindings other extensions may replace.
A compile-time macro: you do not import it, the call itself is removed at build time, and it is mandatory in every base component.
What it does
A base component is private by default. Every top-level binding becomes ordinary component state that its own template can read, and only the names listed here become part of the override API.
const props = defineProps<{ name: string }>();
const clicks = ref(0);
const greeting = computed(() => `Hello ${props.name}`);
swDefinePublic({ greeting });greeting is public: an override can replace it with swDefineOverride(). clicks and props stay private - still readable in this component's own template, not part of the contract.
Pass {} for a component that exposes nothing:
swDefinePublic({});Rules
Shorthand bindings only. The key always equals the local binding name. Renaming ({ total: count }), string keys, computed keys and spreads are rejected at build time.
Once, at the top level. A second top-level call is rejected. A call nested inside a function or block is not recognised as the marker, so the file is treated as having none.
Base files only. In an .override.vue file this macro is rejected; use swDefineOverride().
No defineExpose(). The transform generates the component's defineExpose() call from this list, so an authored defineExpose() is rejected.
A binding must not share a declared prop's name. See troubleshooting.