Coder Social home page Coder Social logo

vite-plugin-handlebars's People

Contributors

alexlafroscia avatar bohreromir avatar dependabot[bot] avatar naranjamecanica avatar nickgraffis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vite-plugin-handlebars's Issues

Upgrade to support Vite 5

Thank you for your awesome work on this plug-in.

After upgrading to Vite 5, the following warnings appear after startup:

plugin 'handlebars' uses deprecated 'enforce' option. Use 'order' option instead.
plugin 'handlebars' uses deprecated 'transform' option. Use 'handler' option instead.

Support `.hbs` extensions for entry files

As far as I can tell, Vite makes a hard assumption that the file it starts to resolve linked files from is an HTML file. There is code I've seen internally that validates that the extension is .html.

It would be nice if we could use .hbs for these files, if we're going to have Handlebars syntax in them, just for the purposes of syntax highlighting and the like.

I'm not sure what allowing non-html files at the "top level" would look like, but it would be really nice to support!

[Security] Workflow ci.yml is using vulnerable action actions/checkout

The workflow ci.yml is referencing action actions/checkout using references v1. However this reference is missing the commit a6747255bd19d7a757dbdda8c654a9f84db19839 which may contain fix to the some vulnerability.
The vulnerability fix that is missing by actions version could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider to update the reference to the action.

Support relative links to assets from partials

I would really like to be able to support relative links in partials that are resolved relative to the partial itself rather than the file that the partial is injected into. This would make it nicer to keep, for example, CSS and JS files related to that partial in a directory with the partial itself.

Ideally, this would happen by Vite exposing the required logic to resolve these links in such a way that they can be run on the .hbs partial files. I looked into this a bit, and that doesn't seem possible (at this time, at least).

We could parse and re-write the links within this plugin, but it would be really nice to re-use the logic from Vite here instead...

I looked into running transformIndexHtml on each partial, which did not work initially but is probably the best way to go. I'm not sure if there would be pitfalls here due to the plugin potentially running the hbs transform on the partials before they are actually injected, though. There's investigation to do here!

Another option would be to provide a helper that solves this. It would do something similar to the currently-provided (and intended-to-be-removed) resolve-from-root helper, but something like resolve-relative, that handles re-writing the path. This is probably easier than trying to run transformIndexHtml on each partial before injecting them.

pagePath not properly resolved?

I have a setup with this configuration:

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

const pageData = {
  "/src/pages/index.html": {
    title: "Homepage"
  },
  "/src/pages/subpage/index.html": {
    title: "Subpage"
  }
};

const handlebarsOptions = {
  context(pagePath) {
    console.log("pagePath =", pagePath);
    return pageData[pagePath];
  },
  partialDirectory: resolve(__dirname, "src/pages/partials")
};

export default {
  plugins: [handlebars(handlebarsOptions)]
};

A codesandbox is here:
https://codesandbox.io/s/vite-with-handlebars-61te7

As the terminal shows, the console.log does not pick up the current configuration.

What am I doing wrong?

Reloading not happening when partial changes (windows 10)

When I hit save the therminal shows [vite] page reload partiasl/fine.html but the browser never reloads.

I did a investigation I found out that there is a check if the file changed must trigger a full-reload, and that check is broken. At least at windows.

The check:
image

The values (set and filename) being checked:
image

For some reason, the slashes are the being misplaced.

I have noticed that the problem appear immediately after the partial filename has been added to the set

image

image

My vite config is the following:

export default defineConfig({
  root: "src",
  assetsInclude: ["/src/partials/*"],
  plugins: [
    handlebarsPlugin({
      partialDirectory: resolve(__dirname, "src/partials"),
    }),
  ],
});

Suggestion:
Remove the check partialsSet.has(file), looks like its no necessary

resolve-from-root return physic path on windows

OS: Windows 11
Node v20.9.0 & v20.11.1

It works fine on Mac OS, however the output for {{resolve-from-root ''relative/path/to/file.ext""}} is totally wrong on Windows. It will be return "C:\relative\path\to\file.ext"

Partials only work on index.html

I basically have the same issue raised in this stack overflow, but the one response does not solve my issue -> https://stackoverflow.com/questions/74877312/vite-plugin-handlebars-not-working-with-multipage-set-up

I can only get partials to work in the index.html file at my project's root, which seems to make this plugin not very useful as only one single file in my project can receive partials. How can we use this plugin in order to use partials in both the index.html file at the root of the project and files in the public directory?

Here is my vite.config:

import { defineConfig } from 'vite'
import handlebars from 'vite-plugin-handlebars';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [handlebars({
    partialDirectory: resolve(__dirname, 'public/partials')
  })],
})

Here is my project structure:

├── package.json
├── vite.config.js
├── index.html
└── public
    ├── about
        ├── about.html
    ├── contact
        ├── contact.html
    └── partials
        ├── header.hbs
        └── footer.hbs

Basically, {{> header }} works as expected on the index.html page, but shows up as raw text on the about.html page and the contact.html pages. Am I missing something obvious in my config?I built my project using the Vanilla JS scaffold right from the Vite docs.

Watch partial files for changes

I'm not sure exactly how this would work, but it would be really nice to (somehow) inform Vite of the fact that the Handlebars partials are part of the "dependency graph" of the page being viewed in the browser.

Currently, it seems like the changes are processed immediately, but the browser doesn't actually refresh in real-time.

I'm not actually sure why the dev server picks up the changes to a partial without re-starting. Maybe Vite is monitoring the entire local directory? Or is just re-running the bundling step on every browser refresh? Not sure right now.


  • Automatically trigger browser refresh when a partial changes

Nested Partials are Not Found

Unfortunately it doesn't work with 1.2.0 and 1.3.0. Maybe I missed smth, this is my config from the readme:

import { resolve } from 'path';
import handlebars from 'vite-plugin-handlebars';

export default {
  plugins: [
    handlebars({
      partialDirectory: resolve(__dirname, 'partials'),
    }),
  ],
};

`{{>head/head}}``this is in my startpage.html.

When I do a yarn build I got this error:

[vite:build-html] The partial head could not be found
file: C:/Projekte/Others/smth/pages/startpage/startpage.html
error during build:
Error: The partial head/head could not be found

Originally posted by @Chris2011 in #30 (comment)

feature request: ability to import as precompiled templates

It would be great if there were an option to return a precompiled template instead of raw html.

This would allow handlebar files to be imported and the resulting precompiled templates reused with different contexts.

import template from './template.hbs`

const htmlJoe = template({ name: 'Joe' })
const htmlJane = template({ name: 'Jane' })

[Security] Workflow ci.yml is using vulnerable action actions/checkout

The workflow ci.yml is referencing action actions/checkout using references v1. However this reference is missing the commit a6747255bd19d7a757dbdda8c654a9f84db19839 which may contain fix to the some vulnerability.
The vulnerability fix that is missing by actions version could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider to update the reference to the action.

wrong path in dist when the public folder is used

Expected: suppose we have a file public/test/index.html, the file should be copied to dist/test/index.html.
Current Beavior: it's copied to dist/public/test/index.html.
Config:

import { resolve } from 'path'
import { defineConfig } from 'vite'
import handlebars from 'vite-plugin-handlebars';

export default defineConfig({
  plugins: [
    handlebars({partialDirectory: resolve(__dirname, 'partials')})
  ],
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, 'index.html'),
        standards: resolve(__dirname, 'public/test/index.html')
      }
    }
  }
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.