@vitejs/plugin-vue npm

Note: requires @vue/compiler-sfc as peer dependency. This is largely a port of rollup-plugin-vue with some vite-specific tweaks.

  1. // vite.config.js
  2. import vue from '@vitejs/plugin-vue'
  3. export default {
  4. plugins: [vue()]
  5. }

Options

  1. export interface Options {
  2. include?: string | RegExp | (string | RegExp)[]
  3. exclude?: string | RegExp | (string | RegExp)[]
  4. ssr?: boolean
  5. isProduction?: boolean
  6. // options to pass on to @vue/compiler-sfc
  7. script?: Partial<SFCScriptCompileOptions>
  8. template?: Partial<SFCTemplateCompileOptions>
  9. style?: Partial<SFCStyleCompileOptions>
  10. }

Example for passing options to @vue/compiler-dom:

  1. import vue from '@vitejs/plugin-vue'
  2. export default {
  3. plugins: [
  4. vue({
  5. template: {
  6. compilerOptions: {
  7. // ...
  8. }
  9. }
  10. })
  11. ]
  12. }

Example for transforming custom blocks

  1. import vue from '@vitejs/plugin-vue'
  2. const vueI18nPlugin = {
  3. name: 'vue-i18n',
  4. transform(code, id) {
  5. if (!/vue&type=i18n/.test(id)) {
  6. return
  7. }
  8. if (/\.ya?ml$/.test(id)) {
  9. code = JSON.stringify(require('js-yaml').safeLoad(code.trim()))
  10. }
  11. return `export default Comp => {
  12. Comp.i18n = ${code}
  13. }`
  14. }
  15. }
  16. export default {
  17. plugins: [vue(), vueI18nPlugin]
  18. }

License

MIT