{"_id":"@cpulvermacher/vite-plugin-handlebars","_rev":"4-0522c87e6a5e94ec0ee75d4e41f8ddd8","name":"@cpulvermacher/vite-plugin-handlebars","dist-tags":{"latest":"1.5.0"},"versions":{"1.4.1":{"name":"@cpulvermacher/vite-plugin-handlebars","version":"1.4.1","keywords":["vite","vite-plugin","handlebars"],"author":{"url":"https://github.com/yoichiro","name":"Yoichiro Tanaka","email":"yoichiro6642@gmail.com"},"license":"MIT","_id":"@cpulvermacher/vite-plugin-handlebars@1.4.1","maintainers":[{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"}],"contributors":[{"url":"https://github.com/cpulvermacher","name":"Christian Pulvermacher"}],"homepage":"https://github.com/cpulvermacher/vite-plugin-handlebars","bugs":{"url":"https://github.com/cpulvermacher/vite-plugin-handlebars/issues"},"dist":{"shasum":"eea55c7620fbe5568dcb4ac9189d5bb8f21d00a8","tarball":"https://registry.npmjs.org/@cpulvermacher/vite-plugin-handlebars/-/vite-plugin-handlebars-1.4.1.tgz","fileCount":7,"integrity":"sha512-6swVnFHCJh1omZjI5DHq7z8II1zVwg5Fcp0LHMcoxLaa6H4zIH0caX46fZb++WV04o2Mc2V1FmlBlkqf35mXug==","signatures":[{"sig":"MEUCICSagoa1BY4yotcjcl4OodrTypy/QrJuYgCWygN8gCEMAiEA23Sy04m2vtdw3ufPrfkwZ2fu+1d61ug3Gx9Ga/IcvmU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22540},"type":"module","types":"dist/index.d.ts","engines":{"node":"^18.0.0 || >=20.0.0"},"exports":"./dist/index.js","gitHead":"8c2cd4aedd3f1bdf5ab3f7d476f7e47a6b1bcc91","scripts":{"test":"vitest","build":"tsc","prepare":"npm run build","type-check":"tsc --noEmit","integration-dev":"npm run build && vite --config integration/vite.config.ts","integration-build":"npm run build && vite build --config integration/vite.config.ts","integration-preview":"npm run build && vite preview --config integration/vite.config.ts"},"_npmUser":{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"},"repository":{"url":"git+https://github.com/cpulvermacher/vite-plugin-handlebars.git","type":"git"},"_npmVersion":"10.9.4","description":"A maintenance fork of [@yoichiro/vite-plugin-handlebars](https://github.com/yoichiro/vite-plugin-handlebars) with updated dependencies and support for vite 7/8. This is a plugin that provides convenient features for using Handlebars with Vite.","directories":{},"_nodeVersion":"22.22.0","dependencies":{"handlebars":"^4.7.9"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.1.5","prettier":"^3.3.2","typescript":"^5.5.2","@types/node":"^20.14.9"},"peerDependencies":{"vite":">=5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/vite-plugin-handlebars_1.4.1_1777093550888_0.10565832367244266","host":"s3://npm-registry-packages-npm-production"}},"1.4.2":{"name":"@cpulvermacher/vite-plugin-handlebars","version":"1.4.2","keywords":["vite","vite-plugin","handlebars"],"author":{"url":"https://github.com/yoichiro","name":"Yoichiro Tanaka","email":"yoichiro6642@gmail.com"},"license":"MIT","_id":"@cpulvermacher/vite-plugin-handlebars@1.4.2","maintainers":[{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"}],"contributors":[{"url":"https://github.com/cpulvermacher","name":"Christian Pulvermacher"}],"homepage":"https://github.com/cpulvermacher/vite-plugin-handlebars","bugs":{"url":"https://github.com/cpulvermacher/vite-plugin-handlebars/issues"},"dist":{"shasum":"6cdbbfcde76da1044ee5e844f762f8aaa6138397","tarball":"https://registry.npmjs.org/@cpulvermacher/vite-plugin-handlebars/-/vite-plugin-handlebars-1.4.2.tgz","fileCount":7,"integrity":"sha512-y9LeuXDILLGBj1K8vHabclkeTL1ozOe2drjBLP2JEhOO2jgixop800PPGXVdVQ/4tAR5pERMx37GTPjmwXdd3Q==","signatures":[{"sig":"MEUCIQCGQjR+Z/MNsgN0nTU3dvMXPqBtZH2bJ9/nwPQHz7EyvAIgOjAc1VsxfBXQfEmFZcVx6ekyDoC1GONUNponVNsQtiI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22505},"type":"module","types":"dist/index.d.ts","engines":{"node":"^18.0.0 || >=20.0.0"},"exports":"./dist/index.js","gitHead":"860c7d66bed4b230b09534f697c9a671e438530a","scripts":{"test":"vitest","build":"tsc","prepare":"npm run build","type-check":"tsc --noEmit","integration-dev":"npm run build && vite --config integration/vite.config.ts","integration-build":"npm run build && vite build --config integration/vite.config.ts","integration-preview":"npm run build && vite preview --config integration/vite.config.ts"},"_npmUser":{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"},"repository":{"url":"git+https://github.com/cpulvermacher/vite-plugin-handlebars.git","type":"git"},"_npmVersion":"10.9.4","description":"A maintenance fork of @yoichiro/vite-plugin-handlebars with updated dependencies and support for vite 7/8. This is a plugin that provides convenient features for using Handlebars with Vite.","directories":{},"_nodeVersion":"22.22.0","dependencies":{"handlebars":"^4.7.9"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.10","vitest":"^4.1.5","prettier":"^3.3.2","typescript":"^5.5.2","@types/node":"^20.14.9"},"peerDependencies":{"vite":">=5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/vite-plugin-handlebars_1.4.2_1777126188326_0.24068005337389975","host":"s3://npm-registry-packages-npm-production"}},"1.4.3":{"name":"@cpulvermacher/vite-plugin-handlebars","version":"1.4.3","keywords":["vite","vite-plugin","handlebars"],"author":{"url":"https://github.com/yoichiro","name":"Yoichiro Tanaka","email":"yoichiro6642@gmail.com"},"license":"MIT","_id":"@cpulvermacher/vite-plugin-handlebars@1.4.3","maintainers":[{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"}],"contributors":[{"url":"https://github.com/cpulvermacher","name":"Christian Pulvermacher"}],"homepage":"https://github.com/cpulvermacher/vite-plugin-handlebars","bugs":{"url":"https://github.com/cpulvermacher/vite-plugin-handlebars/issues"},"dist":{"shasum":"ca8115f7e5cc713dc696a99d19156ba7932d1d4f","tarball":"https://registry.npmjs.org/@cpulvermacher/vite-plugin-handlebars/-/vite-plugin-handlebars-1.4.3.tgz","fileCount":7,"integrity":"sha512-aDK4V4gWFPVD2MwCKCBW2bP7fqf3Th10rVgp2HfBt4DCQijjErguuh49IVkBEBvYQGJnzIlJ3YAznKVapgthzQ==","signatures":[{"sig":"MEUCIQCMW46A2MDDbnMnVYQ5wScBkXrZzUAetK0xbTuhbkTG2QIgAzzX0+uLIpmYRhKLXTy3ZcXVJKa2i8k13Q4cBWObRe4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22534},"type":"module","types":"dist/index.d.ts","engines":{"node":"^18.0.0 || >=20.0.0"},"exports":"./dist/index.js","gitHead":"1e0a8084d04f157c89292d08acb8730401389f68","scripts":{"test":"vitest","build":"tsc","prepare":"npm run build","type-check":"tsc --noEmit","integration-dev":"npm run build && vite --config integration/vite.config.ts","integration-build":"npm run build && vite build --config integration/vite.config.ts","integration-preview":"npm run build && vite preview --config integration/vite.config.ts"},"_npmUser":{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"},"repository":{"url":"git+https://github.com/cpulvermacher/vite-plugin-handlebars.git","type":"git"},"_npmVersion":"10.9.4","description":"A maintenance fork of @yoichiro/vite-plugin-handlebars with updated dependencies and support for vite 7/8. This is a plugin that provides convenient features for using Handlebars with Vite.","directories":{},"_nodeVersion":"22.22.0","dependencies":{"handlebars":"^4.7.9"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^8.0.10","vitest":"^4.1.5","prettier":"^3.3.2","typescript":"^5.5.2","@types/node":"^20.14.9"},"peerDependencies":{"vite":"^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"},"_npmOperationalInternal":{"tmp":"tmp/vite-plugin-handlebars_1.4.3_1778492559385_0.026477861083821663","host":"s3://npm-registry-packages-npm-production"}},"1.5.0":{"name":"@cpulvermacher/vite-plugin-handlebars","version":"1.5.0","author":{"name":"Yoichiro Tanaka","email":"yoichiro6642@gmail.com","url":"https://github.com/yoichiro"},"contributors":[{"name":"Christian Pulvermacher","url":"https://github.com/cpulvermacher"}],"repository":{"type":"git","url":"git+https://github.com/cpulvermacher/vite-plugin-handlebars.git"},"homepage":"https://github.com/cpulvermacher/vite-plugin-handlebars","bugs":{"url":"https://github.com/cpulvermacher/vite-plugin-handlebars/issues"},"dependencies":{"handlebars":"^4.7.9"},"devDependencies":{"@types/node":"^20.14.9","prettier":"^3.3.2","typescript":"^5.5.2","vite":"^8.0.16","vitest":"^4.1.8"},"peerDependencies":{"vite":"^6.3.0 || ^7.0.0 || ^8.0.0"},"engines":{"node":"^18.0.0 || >=20.0.0"},"scripts":{"type-check":"tsc --noEmit","build":"tsc","prepare":"npm run build","test":"vitest","integration-dev":"npm run build && vite --config integration/vite.config.ts","integration-build":"npm run build && vite build --config integration/vite.config.ts","integration-preview":"npm run build && vite preview --config integration/vite.config.ts"},"types":"dist/index.d.ts","license":"MIT","exports":"./dist/index.js","type":"module","keywords":["vite","vite-plugin","handlebars"],"_id":"@cpulvermacher/vite-plugin-handlebars@1.5.0","gitHead":"5aa57fe76cf842a2ed74a24f3bdfd5c99c8156d6","description":"A maintenance fork of @yoichiro/vite-plugin-handlebars that makes Vite a peer dependency and keeps things up to date. Use `1.4.x` as a drop-in replacement for the original plugin (supports Vite 5-8), or `1.5.x` for slightly faster builds (supports Vite 6.","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-fCg7A7oKC+oTvlaR7pwn1USkHZpQItGbk4hab4eqewZjaMGE+PiUSvWi21pLXzzbfAUprkbTT3ZCwBoOA1yqrA==","shasum":"2f8600e53ce8a2171126f294754cbb475ffd5121","tarball":"https://registry.npmjs.org/@cpulvermacher/vite-plugin-handlebars/-/vite-plugin-handlebars-1.5.0.tgz","fileCount":7,"unpackedSize":22824,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCOiGEDQ/GJfPvdjW7I648JweqJxhNZaNoe6ZU/bkYFTAIhAIFxm7Z0mZjOP4+IgKEPc/P6LnDOPmCuLriETN5+vjml"}]},"_npmUser":{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"},"directories":{},"maintainers":[{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/vite-plugin-handlebars_1.5.0_1781315405613_0.9080216542069841"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-25T05:05:50.742Z","modified":"2026-06-13T01:50:05.877Z","1.4.1":"2026-04-25T05:05:51.015Z","1.4.2":"2026-04-25T14:09:48.527Z","1.4.3":"2026-05-11T09:42:39.519Z","1.5.0":"2026-06-13T01:50:05.754Z"},"bugs":{"url":"https://github.com/cpulvermacher/vite-plugin-handlebars/issues"},"author":{"name":"Yoichiro Tanaka","email":"yoichiro6642@gmail.com","url":"https://github.com/yoichiro"},"license":"MIT","homepage":"https://github.com/cpulvermacher/vite-plugin-handlebars","keywords":["vite","vite-plugin","handlebars"],"repository":{"type":"git","url":"git+https://github.com/cpulvermacher/vite-plugin-handlebars.git"},"description":"A maintenance fork of @yoichiro/vite-plugin-handlebars that makes Vite a peer dependency and keeps things up to date. Use `1.4.x` as a drop-in replacement for the original plugin (supports Vite 5-8), or `1.5.x` for slightly faster builds (supports Vite 6.","contributors":[{"name":"Christian Pulvermacher","url":"https://github.com/cpulvermacher"}],"maintainers":[{"name":"cpulvermacher","email":"christian.pulvermacher@posteo.de"}],"readme":"# @cpulvermacher/vite-plugin-handlebars\n\nA maintenance fork of @yoichiro/vite-plugin-handlebars that makes Vite a peer dependency and keeps things up to date.\nUse `1.4.x` as a drop-in replacement for the original plugin (supports Vite 5-8), or `1.5.x` for slightly faster builds (supports Vite 6.3 and newer).\n\nThis is a plugin that provides convenient features for using Handlebars with Vite.\n\n## Features\n\nWith this plugin, the following features are enabled in projects using Vite:\n\n* Handlebars template files can be imported within `.ts` or `.js` files, which is particularly useful in SPA (Single Page Architecture).\n* During the build process, index files are processed as Handlebars template files. This feature is especially useful in MPA (Multi Page Architecture).\n\n### Example of SPA\n\nAs an example of SPA, suppose you have the following Handlebars template file (`templates/card.hbs`):\n\n```html\n<div class=\"card\">\n  <p>{{ message }}</p>\n</div>\n```\n\nWith this plugin, you can import and use `card.hbs` as follows:\n\n```javascript\nimport template from 'templates/card.hbs';\n\nconst card = template({ message: 'Hello, world!' });\nconst elem = document.getElementById('target');\nelem.innerHTML = card;\n```\n\nAlso, suppose you have the following partial file (`templates/partials/footer.hbs`):\n\n```html\n<div class=\"footer\">\n  <p>Powered by Vite and Handlebars.</p>\n</div>\n```\n\nThen, include it in the `card.hbs` file as follows:\n\n```html\n<div class=\"card\">\n  <p>{{ message }}</p>\n  {{> footer}}\n</div>\n```\n\nThis plugin automatically loads the `footer.hbs` file and includes it in the `card.hbs` file.\n\n### Example of MPA\n\nAs an example of MPA, suppose you have the following index file (`index.html`):\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>...</head>\n<body>\n    <p>{{ upper-case message }}</p>\n    {{> footer}}\n</body>\n</html>\n```\n\nAlso, suppose you have the following partial file (`partials/footer.hbs`):\n\n```html\n<div class=\"footer\">\n  <p>Powered by Vite and Handlebars.</p>\n</div>\n```\n\nNext, create the following `vite.config.js` file:\n\n```javascript\nimport { defineConfig } from 'vite';\nimport handlebarsPlugin from '@cpulvermacher/vite-plugin-handlebars';\nimport path from 'path';\n\nexport default defineConfig({\n  plugins: [\n    handlebarsPlugin({\n      partialsDirectoryPath: path.resolve(__dirname, 'partials'),\n      transformIndexHtmlOptions: {\n        context: () => ({\n          message: 'Hello, world!'\n        }),\n        helpers: {\n          'upper-case': (str) => str.toUpperCase(),\n        },\n      },\n    })\n  ]\n});\n```\n\nAs a result, the `index.html` file generated by running `vite build` will be as follows:\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>...</head>\n<body>\n    <p>HELLO, WORLD!</p>\n    <div class=\"footer\">\n      <p>Powered by Vite and Handlebars.</p>\n    </div>\n</body>\n</html>\n```\n\n# Installation\n\n```shell\nnpm install @cpulvermacher/vite-plugin-handlebars --save-dev\n```\n\n# Usage\n\nTo use this plugin in your Vite project, modify your `vite.config.js` or `vite.config.ts` file as follows:\n\n```javascript\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport handlebarsPlugin from '@cpulvermacher/vite-plugin-handlebars';\n\nexport default defineConfig({\n  plugins: [\n    handlebarsPlugin()\n  ]\n});\n```\n\n## Options\n\nThis plugin can be configured with the following options:\n\n* `templateFileExtension` (string) - Specifies the extension of Handlebars template files. Defaults to `hbs` if omitted.\n* `partialsDirectoryPath` (string) - Specifies the path to the directory containing partial template files to be included in Handlebars template files. If omitted, partial template files are not registered.\n* `optimizePartialRegistration` (boolean) - Set to true to optimize the partial registration. This option is effective only when `partialsDirectoryPath` is set. If omitted, the plugin does not optimize the partial registration. If true, the plugin does not register the partials that are already registered.\n* `compileOptions` (object) - Specifies the options to be passed to the Handlebars compiler. If omitted, the default options are used.\n* `transformIndexHtmlOptions` (object) - This is an option to specify when treating the index file as a Handlebars template file during the Vite build process. If this option is not specified, the index file will not be transformed.\n\nThese options can be specified as arguments to the `handlebarsPlugin` function. Below is an example that specifies `handlebars` as the template file extension and `templates/partials` as the directory containing partial template files.\n\n```javascript\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport handlebarsPlugin from '@cpulvermacher/vite-plugin-handlebars';\nimport path from 'path';\n\nexport default defineConfig({\n  plugins: [\n    handlebarsPlugin({\n      templateFileExtension: 'handlebars',\n      partialsDirectoryPath: path.resolve(__dirname, 'templates', 'partials'),\n      optimizePartialRegistration: true,\n    })\n  ]\n});\n```\n\nThe `compileOptions` are the various options applied when compiling template files in Handlebars. For details on each option, please refer to the [Handlebars documentation](https://handlebarsjs.com/api-reference/compilation.html#handlebars-compile-template-options).\n\nWhen building with the Vite build or preview command, if you want to treat the index file (typically the `index.html` file) as a Handlebars template file and perform a transformation, specify the `transformIndexHtmlOptions` option. This option is an object that can contain the following properties:\n\n* `context` (object or function) - Specifies the context object to be passed to the Handlebars template file. If a function is specified, the function is called and the return value is used as the context object.\n* `helpers` (object) - Specifies the helper functions to be passed to the Handlebars template file.\n\nIf you want to transform the index file as a Handlebars template file without registering any context or helpers, specify an empty object as shown below.\n\n```javascript\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport handlebarsPlugin from '@cpulvermacher/vite-plugin-handlebars';\nimport path from 'path';\n\nexport default defineConfig({\n  plugins: [\n    handlebarsPlugin({\n      templateFileExtension: 'handlebars',\n      partialsDirectoryPath: path.resolve(__dirname, 'templates', 'partials'),\n      transformIndexHtmlOptions: {},\n    })\n  ]\n});\n```\n\nPlease note that the `context` option and `helpers` option specified in the `transformIndexHtmlOptions` are only applied during Vite's build process. They are not applied when importing Handlebars template files using import in `.ts` or `.js` files.\n\nAdditionally, when there are multiple index files in an MPA, use `rollupOptions` as shown below.\n\n```javascript\nexport default defineConfig({\n  ...\n  build: {\n    rollupOptions: {\n      input: {\n        index: resolve(__dirname, 'index.html'),\n        alternative: resolve(__dirname, 'alternative.html'),\n      },\n    },\n  },\n});\n```\n\n# Samples\n\nThe `integration` directory contains a sample Vite project using this plugin. You can start this sample project by following these steps:\n\n```sh\n$ git clone https://github.com/cpulvermacher/vite-plugin-handlebars.git\n$ cd vite-plugin-handlebars\n$ npm install\n$ npm run integration-preview\n```\n\nAfter the preview server starts, please access `http://localhost:4173` in your web browser.\n\n# Contributing\n\nIf you would like to contribute to this plugin, please follow these steps:\n\n1. Register an issue and describe what you would like to contribute.\n2. When you want to contribute by sending code, fork this repository, create a new branch, make your code changes, and submit a pull request.\n\n# License\n\nFor the license of this plugin, please refer to the [LICENSE](https://github.com/cpulvermacher/vite-plugin-handlebars/blob/main/LICENSE) file.\n","readmeFilename":"README.md"}