/** * Requires @vitejs/plugin-vue@^5.1.0 */ features?: { /** * Enable reactive destructure for `defineProps`. * - Available in Vue 3.4 and later. * - **default:** `false` in Vue 3.4 (**experimental**), `true` in Vue 3.5+ */ propsDestructure?: boolean /** * Transform Vue SFCs into custom elements. * - `true`: all `*.vue` imports are converted into custom elements * - `string | RegExp`: matched files are converted into custom elements * - **default:** /\.ce\.vue$/ */ customElement?: boolean | string | RegExp | (string | RegExp)[] /** * Set to `false` to disable Options API support and allow related code in * Vue core to be dropped via dead-code elimination in production builds, * resulting in smaller bundles. * - **default:** `true` */ optionsAPI?: boolean /** * Set to `true` to enable devtools support in production builds. * Results in slightly larger bundles. * - **default:** `false` */ prodDevtools?: boolean /** * Set to `true` to enable detailed information for hydration mismatch * errors in production builds. Results in slightly larger bundles. * - **default:** `false` */ prodHydrationMismatchDetails?: boolean /** * Customize the component ID generation strategy. * - `'filepath'`: hash the file path (relative to the project root) * - `'filepath-source'`: hash the file path and the source code * - `function`: custom function that takes the file path, source code, * whether in production mode, and the default hash function as arguments * - **default:** `'filepath'` in development, `'filepath-source'` in production */ componentIdGenerator?: | 'filepath' | 'filepath-source' | (( filepath: string, source: string, isProduction: boolean | undefined, getHash: (text: string) => string, ) =>string) }
// `script`, `template` and `style` are lower-level compiler options // to pass on to respective APIs of `vue/compiler-sfc`
Note that only attribute values that are static strings are transformed. Otherwise, you'd need to import the asset manually, e.g. import imgUrl from '../image.png'.
const vueI18nPlugin = { name: 'vue-i18n', transform(code, id) { // if .vue file don't have <i18n> block, just return if (!/vue&type=i18n/.test(id)) { return } // parse yaml if (/\.ya?ml$/.test(id)) { code = JSON.stringify(yaml.load(code.trim())) } // mount the value on the i18n property of the component instance return`export default Comp => { Comp.i18n = ${code} }` }, }
Vue 3.2 introduces the defineCustomElement method, which works with SFCs. By default, <style> tags inside SFCs are extracted and merged into CSS files during build. However when shipping a library of custom elements, it may be desirable to inline the styles as JavaScript strings and inject them into the custom elements' shadow root instead.
Starting in 1.4.0, files ending with *.ce.vue will be compiled in "custom elements" mode: its <style> tags are compiled into inlined CSS strings and attached to the component as its styles property: