riot / rollup-plugin-riot

Rollup Plugin for Riot
https://www.npmjs.com/package/rollup-plugin-riot
MIT License
26 stars 9 forks source link

Riot, Vite and Pug #124

Closed wgehner closed 3 months ago

wgehner commented 3 months ago

Hello,

as a longtime Riot user I want to make this work with Vite and Pug.

Riot-Vite-[NoPug] works thanks to https://dev.to/steeve/riotjs-vitejs-tutorial-fpn

My component does not work when written in pug. Run fails with 'Premature end of file' error.

My attempt is at https://github.com/wgehner/riot-vite-pug More details there.

Please help.

GianlucaGuarini commented 3 months ago

You are just missing the template option in your rollup plugins config. Your rollup config file should look like this:

//import vituum from 'vituum'
//import pug from '@vituum/vite-plugin-pug'
import { defineConfig } from "vite";
import riot from "rollup-plugin-riot";
import { registerPreprocessor } from "@riotjs/compiler";
import pug from "pug";

registerPreprocessor("template", "pug", function (code, { options }) {
  const { file } = options;
  console.log("Preprocess the template", file);
  return {
    code: pug.render(code),
    // no sourcemap here
    map: null,
  };
});

export default defineConfig({
  root: process.cwd() + "/src",
  plugins: [
    riot({
      template: "pug",
    }),
  ],
  build: {
    outDir: "../dist",
    minify:
      "esbuild" /** https://vitejs.dev/config/build-options.html#build-minify */,
    target:
      "esnext" /** https://vitejs.dev/config/build-options.html#build-target */,
  },
});
wgehner commented 3 months ago

Thank you, works like a charm!