vite-plugin-nunjucks icon indicating copy to clipboard operation
vite-plugin-nunjucks copied to clipboard

Processing files other than index.html?

Open zgoda opened this issue 2 years ago • 5 comments

I have a nunjucks template in about/index.njk and this plugin seems to not process it at all. Or I misunderstood the purpose of this plugin?

zgoda avatar Nov 10 '21 17:11 zgoda

You are right. Plugin transforms only .html file. I will add .njk support.

Jax-p avatar Nov 10 '21 17:11 Jax-p

Hey, importing .njk files in templates (like: {% extends "src/html/@layout.njk" %}) works fine. However, the entry point as .njk is not working due to Rollup and I am not sure why yet. I'm afraid it's more of a Vite/Rollup issue.

If anyone has an idea to make .njk work as an entry point for Rollup, I'd be happy.

Jax-p avatar Nov 29 '21 08:11 Jax-p

This is quite unfortunate. I've seen that not many (or any) of these template engines work in Vite without the (main) entry-point(s) as *.html.

I've tried with Rollup options (rollupOptions), but no luck there either:

import { resolve } from "path";
import nunjucks from "vite-plugin-nunjucks";

const cwd = process.cwd();

/**
 * @type {import("vite").UserConfig}
 */
export default {
  build: {
    emptyOutDir: true,
    manifest: true,
    outDir: resolve(cwd, "dist"),
    rollupOptions: {
      input: {
        index: resolve(cwd, "src", "index.njk"),
      },
    },
    sourcemap: true,
  },
  plugins: [nunjucks()],
  root: resolve(cwd, "src"),
};

x80486 avatar Mar 28 '22 17:03 x80486

What is the status of this ? im using storybook and vite and tried this to add support for njk file imports but as its only working with index.html files im a bit stumbled to how to solve this is it even possible ?

robgha01 avatar Jun 09 '22 11:06 robgha01

Any help on this would be appreciated by someone who is in touch with new versions of Vite.

Jax-p avatar Jan 27 '23 20:01 Jax-p