slidev icon indicating copy to clipboard operation
slidev copied to clipboard

[Feature Request] Allow build with multiple markdown entries

Open shigma opened this issue 3 years ago • 11 comments

Is your feature request related to a problem? Please describe. My team uses slidev to present slides every week, and our project directory looks like this:

root
  components
  slides
    20210710.md
    20210717.md
    20210724.md
  package.json

I want to build all this slides into a SPA but it seems that slidev only supports building with single entry.

Describe the solution you'd like

slidev build [file1] [file2]
slidev build [directory]

Describe alternatives you've considered N/A

shigma avatar Jul 25 '21 06:07 shigma

Why not just running the script multiple times?

antfu avatar Jul 25 '21 09:07 antfu

Why not just running the script multiple times?

Because the assets that slidev generates could have been shared, but it didn't.

dist
  assets
    vendor.xxxxxx.js
  index.html

What I want is

dist
  assets
    vendor.xxxxxx.js
    1.xxxxxx.js (for 20210710.md)
    2.xxxxxx.js (for 20210717.md)
    3.xxxxxx.js (for 20210724.md)
  20210710.html
  20210717.html
  20210724.html

And each of the generated HTML file shares something in common (vendor).

shigma avatar Jul 25 '21 10:07 shigma

I guess this could be done by providing multiple input entries to Vite's build. PR Welcome.

antfu avatar Sep 17 '21 21:09 antfu

cross referencing https://github.com/slidevjs/slidev/issues/479 https://github.com/slidevjs/slidev/issues/505

twitwi avatar Apr 13 '22 17:04 twitwi

I made an implementation that is working You can access at: https://github.com/gabriel-del/slidev All feedbacks are welcome

gabriel-del avatar May 05 '22 01:05 gabriel-del

I made an implementation that is working You can access at: https://github.com/gabriel-del/slidev All feedbacks are welcome

This no longer works with @slidev/cli v0.32.3 as it fails to resolve package.json under the presentations folder.

LeonLiuY avatar May 31 '22 06:05 LeonLiuY

It works to my friends, it takes some time to buid, maybe 3min, and maybe you need to use npm instead of yarn. Did you get any error mesage?

gabriel-del avatar May 31 '22 10:05 gabriel-del

Yes I'm using npm.

> ./slidev.sh build

Error: Failed to resolve package "/*******/my-slides/presentations/package.json"
    at resolveImportPath (/*******/my-slides/node_modules/@slidev/cli/dist/chunk-JWGORJY6.js:121:11)
    at getPackageJson (/*******/my-slides/node_modules/@slidev/cli/dist/chunk-N7XL66RP.js:9515:72)
    at getAddons (/*******/my-slides/node_modules/@slidev/cli/dist/chunk-N7XL66RP.js:9518:33)
    at resolveOptions (/*******/my-slides/node_modules/@slidev/cli/dist/chunk-N7XL66RP.js:9600:24)
    at async Object.handler (*****/my-slides/node_modules/@slidev/cli/dist/cli.js:172:19)

LeonLiuY avatar Jun 13 '22 05:06 LeonLiuY

@gabriel-del I get:

6:19:30 PM [vite] Internal server error: EMFILE: too many open files, open '/home/animesh/TrashThings/testing/slidev/node_modules/dagre-d3/node_modules/d3-scale-chromatic/src/categorical/Paired.js'

Animeshz avatar Dec 02 '22 12:12 Animeshz

What this does is just to iterate through the presentations and build each of them independently. But I fact it will not really solve the problem of build files to be different. Some files are the same between the build of 2 different slides, and some are different.

For example ,the generated dist/assets/nav-*.js contains the content of the slides, so it will automatically be different between two different presentation. Also some other files will be different simply because they import that dist/assets/nav-*.js file for exemple, and because the filename of that imported file is different, then that other file is also different.

We can't really also provide multiple input entries to Vite's build because the entrypoint remains the same for all the slides (that file: https://github.com/slidevjs/slidev/blob/main/packages/client/main.ts).

Maybe one option would be to customize how vite manages and creates the files in the bundle to create files that will contains the maximum of shared code and to isolate specific code that only applies to one presentation (I think it mostly concern virtual imports /@slidev/routes, /@slidev/configs...etc.). But I have no idea how this coule be done.

tonai avatar Jan 23 '23 16:01 tonai

I made a PR (https://github.com/slidevjs/slidev/pull/844) to allow the CLI to take multiple entry files when building or exporting. That won't solve the shared assets problem, but this way it doesn't require external script to work.

tonai avatar Jan 24 '23 09:01 tonai