Auto update slides on save, using Vite and Deno #3698
sebmestrallet
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Javascript newbie here, I heard about these shiny tools and wanted to give them a try :
Webpage auto-reloading on file save :
I came across existing projects based on Node.js :
⤷ Creates a Vite project from a template, then adds some minimal Reveal.js code
⤷ A Replit.com template with both Reveal.js & Vite, but the Reveal.js code has drifted significantly (added main.js & style.scss entry points, no more themes)
I wanted auto-reloading & HMR, while using Deno and keeping my existing slides (based on the full hakimel/reveal.js repo).
Here is how I got it working. Skip to the end for the summary.
Installing Deno is very simple, and installing Reveal.js dependencies with Deno too:
# cd to your Reveal.js project then deno install --allow-scripts
If you have a custom theme, let's say
css/theme/source/custom.scss
, you want to compile it to CSS & merge the style definitions withtheme.scss
,layout.scss
,reveal.scss
, etcHere I got an error: "TypeError: fs.fchmod is not a function" at
node_modules/.deno/[email protected]/node_modules/vinyl-fs/lib/file-operations.js:257
. This is because Deno 2 is not quite 100% compatible with Node.js, this function is not available. See issues denoland/deno#24314 and denoland/deno#18218.As workaround, I commented-out this function and its call:
Now
onStat()
ofvinyl-fs
no longer tries to chmod files. CSS themes can be built.Time to test Vite. Create a
vite.config.js
in your project root:Then:
If you get "Error: Too many open files (os error 24)" (fixed in Deno 2.0.3, see PR denoland/deno#26200)
From issue denoland/deno#17757, one solution is to switch from useFsWatch to usePolling. Edit
vite.config.js
:Try again:
Open localhost at the specified port, and bingo, the webpage auto-reloads when you save your
index.html
.However, you may have noticed that tweaking and saving your
dist/theme/custom.css
has no effect. This is becausedist/
is an output folder for both Reveal.js and Vite, and Vite ignores files inside. Let's edit ourvite.config.js
:Now, if run,
vite build
will use another output folder, anddist/theme/custom.css
is watched for you to benefit from Hot Module Replacement (see GIF).Summary
cd
to your hakimel/reveal.js copy, possibly with your custom themes, assets and pluginsdeno install --allow-scripts
deno run build -- css-themes
. Iffs.fchmod
function not recognized, comment-out its definition & it call, then re-rundeno install npm:vite
vite.config.js
that changes the build output directorydeno run --allow-read --allow-write --allow-env --allow-sys --allow-ffi --allow-net --allow-run npm:vite
Let me know if you have some tips & tools to improve your Reveal.js dev environment!
Beta Was this translation helpful? Give feedback.
All reactions