vbenjs / vite-plugin-html

A vite plugin for processing html. It is developed based on lodash template
MIT License
582 stars 93 forks source link

No support for files in directories #37

Open davidmz opened 2 years ago

davidmz commented 2 years ago

I have the following (different) files and 'pages' config:

index.html
about/index.html
pages: [
  { filename: "index.html", template: "index.html" },
  { filename: "about/index.html", template: "about/index.html" },
],

The vite-plugin-html generates the same content for the both files, as in "index.html".

I think, the root of the problem is here — this regexp cuts off all directories and only returns the file base name, which is the same for these files.

anncwb commented 2 years ago

I can't reproduce it, can you give me a reproduction?

davidmz commented 2 years ago

Hi, I tried to create a minimal reproduce and got even stranger result. Please, see https://stackblitz.com/edit/vitejs-vite-p5ytdp?file=vite.config.js&terminal=dev and run "vite build"

It has the "pages" entry commented out in the config, which is probably wrong. With this (commented) config, both files in /dist have the same content.

When I don't comment "pages", the about/index.html file is not created at all. Maybe my "pages" section is wrong?

Topograph commented 2 years ago

Hi, we encounter a very similar problem, after updating the plugin from 2.0.7.

The dev server cannot server any other html file other than the root index.html when the vite-plugin-html is used.

I build a very simple reproduction here: https://github.com/Topograph/vite-html-plugin-reproduction

muuvmuuv commented 2 years ago

Just updated it a little https://stackblitz.com/edit/vitejs-vite-fjtb7m?file=vite.config.js&terminal=dev

Really seems like it just does not write the file to filesystem.

~/projects/vitejs-vite-fjtb7m 1m 39s
❯ npm run build
$ vite build
vite v2.8.4 building for production...                                                       12:17:53
✓ 1 modules transformed.                                                                     12:17:53

 WARN  Generated an empty chunk: "index"                                                     12:17:53

 WARN  Generated an empty chunk: "about_index"                                               12:17:53

dist/about/index.html                 0.14 KiB                                               12:17:53
dist/assets/about_index.04e76c22.js   0.00 KiB / gzip: 0.02 KiB                              12:17:53

~/projects/vitejs-vite-fjtb7m
❯ ls -l dist
total 2
drwxrwxrwx  1  1  staff    1  Mär  17  12:17  assets/      
-rw-rw-rw-  1  1  staff  142  Mär  17  12:17  index.html   

~/projects/vitejs-vite-fjtb7m
❯ ls -l dist/about
ls: cannot access 'dist/about': No such file or directory