vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.29k stars 6.05k forks source link

other types of static assets (such as .txt, .csv) import #883

Closed parrotdance closed 3 years ago

parrotdance commented 3 years ago

Describe the bug

I was try to import something file like .txt, but I got some error message from Vetur.

In VSCode (with Vetur v0.28.0)

  1. create a vite-app with npm init vite-app myproj
  2. create a directory /public and create an empty .txt file at /public/a.txt
  3. add lang="ts" property in script tag
  4. add types.d.ts file with content below:
    declare module "*.txt" {
    const value: string
    export default value
    }
  5. At /components/HelloWorld.vue, import the .txt file with import txt from '/a.txt' inner script tag
  6. Error shows with: Cannot find module '/a.txt' or its corresponding type declarations.Vetur(2307)

Btw I write import txt from '/a.txt' at another .ts file and it feels right. So, In fact, I am not sure about that this bug is about Vetur or Vite.

If the problem is truely about Vite, I mean, it seems like vite has do many things to let users import common static assets out of box, but how can I do if I wanna do the same thing with other type of file? I didn't find any solution in README, and I wonder that will Vite provide any ways to get this through? Just like loader in Webpack?

Reproduction

I think I have provided enough information for this issue, it's okay with create a reproduction if we really need.

System Info

underfin commented 3 years ago

At /components/HelloWorld.vue, import the .txt file with import txt from '/a.txt' inner script tag Error shows with: Cannot find module '/a.txt' or its corresponding type declarations.Vetur(2307)

Look like it is caused by vetur, you can open a issue with it.

it seems like vite has do many things to let users import common static assets out of box, but how can I do if I wanna do the same thing with other type of file? I didn't find any solution in README, and I wonder that will Vite provide any ways to get this through? Just like loader in Webpack?

The issues of static asssets config, you can track here https://github.com/vitejs/vite/issues/810.

parrotdance commented 3 years ago

@underfin Thanks a lot, now I got the right place.