V
V
veryoriginalnickname2021-08-21 21:13:51
Vue.js
veryoriginalnickname, 2021-08-21 21:13:51

How to "configure loader for .vue files" in Vite?

Moved the project from Vue to Vite (both on TS), and after running in cmd "vite", gives similar errors:


error: No loader is configured for ".vue" files: src/views/Auth/Login.vue

Here, of course, it is clear that some kind of loader for .vue needs to be configured. But where to set it up? How to set it up?
The README Vite mentions
Type Support For .vue Imports in TS

but there are examples for some Volar and Vetur, and I'm not sure if this is what I need.
In general, how to configure a loader for .vue files in Vite?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
veryoriginalnickname, 2021-08-21
@veryoriginalnickname

In general, the fact is that Vite does not like imports with @. For example, if you change the import from "@/components/header/header.vue" to "/src/components/header/header.vue", then there will be no error.
upd: in order for @ to work, you need to do this:
tsconfig.json (compilerOptions)

"baseUrl": ".",
    "paths": {
      "@/*": [
        "src/*"
      ]

install
npm i @types/node -D
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from "path"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: [
      { find: '@', replacement: path.resolve(__dirname, 'src') },
    ],
  },
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question