diff --git a/README.md b/README.md index 263c66f..4246543 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# vite-plugin-handlebars-import +# @yoichiro/vite-plugin-handlebars This is a plugin that provides convenient features for using Handlebars with Vite. @@ -46,7 +46,7 @@ This plugin automatically loads the `footer.hbs` file and includes it in the `ca # Installation ```shell -npm install vite-plugin-handlebars-import --save-dev +npm install @yoichiro/vite-plugin-handlebars --save-dev ``` # Usage @@ -56,11 +56,11 @@ To use this plugin in your Vite project, modify your `vite.config.js` or `vite.c ```javascript // vite.config.js import { defineConfig } from 'vite'; -import handlebarsImportPlugin from 'vite-plugin-handlebars-import'; +import handlebarsPlugin from '@yoichiro/vite-plugin-handlebars'; export default defineConfig({ plugins: [ - handlebarsImportPlugin() + handlebarsPlugin() ] }); ``` @@ -72,17 +72,17 @@ This plugin can be configured with the following options: * `templateFileExtension` (string) - Specifies the extension of Handlebars template files. Defaults to `hbs` if omitted. * `partialDirectoryPath` (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. -These options can be specified as arguments to the `handlebarsImportPlugin` function. Below is an example that specifies `handlebars` as the template file extension and `templates/partials` as the directory containing partial template files. +These 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. ```javascript // vite.config.js import { defineConfig } from 'vite'; -import handlebarsImportPlugin from 'vite-plugin-handlebars-import'; +import handlebarsPlugin from '@yoichiro/vite-plugin-handlebars'; import path from 'path'; export default defineConfig({ plugins: [ - handlebarsImportPlugin({ + handlebarsPlugin({ templateFileExtension: 'handlebars', partialDirectoryPath: path.resolve(__dirname, 'templates', 'partials') }) @@ -90,12 +90,25 @@ export default defineConfig({ }); ``` +# Samples + +The `integration` directory contains a sample Vite project using this plugin. You can start this sample project by following these steps: + +```sh +$ git clone https://github.com/yoichiro/vite-plugin-handlebars.git +$ cd vite-plugin-handlebars +$ npm install +$ npm run integration-test +``` + +After the development server starts, please access `http://localhost:5173` in your web browser. + # Contributing If you would like to contribute to this plugin, please follow these steps: 1. Register an issue and describe what you would like to contribute. -2. Fork this repository, create a new branch, make your code changes, and submit a pull request. +2. When you want to contribute by sending code, fork this repository, create a new branch, make your code changes, and submit a pull request. # License diff --git a/integration/src/app.js b/integration/src/app.js index cb108cd..1891f71 100644 --- a/integration/src/app.js +++ b/integration/src/app.js @@ -2,5 +2,5 @@ import template from '../templates/template.handlebars'; window.addEventListener('load', () => { const app = document.getElementById('app'); - app.innerHTML = template({ name: 'Handlebars Import Vite Plugin' }); + app.innerHTML = template({ name: 'Handlebars Vite Plugin' }); }); diff --git a/integration/vite.config.ts b/integration/vite.config.ts index 9663c52..33dcece 100644 --- a/integration/vite.config.ts +++ b/integration/vite.config.ts @@ -1,11 +1,11 @@ import { defineConfig } from 'vite'; -import handlebarsImportPlugin from '../dist/index'; +import handlebarsPlugin from '../dist/index'; import { resolve } from 'path'; export default defineConfig({ root: 'integration', plugins: [ - handlebarsImportPlugin({ + handlebarsPlugin({ templateFileExtension: '.handlebars', partialsDirectoryPath: resolve(__dirname, 'partials'), }), diff --git a/package-lock.json b/package-lock.json index d0a3c4b..ce1e012 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vite-plugin-handlebars-import", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vite-plugin-handlebars-import", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "dependencies": { "handlebars": "^4.7.8", diff --git a/package.json b/package.json index 7faa2b9..218d538 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "vite-plugin-handlebars-import", - "version": "1.0.1", + "name": "@yoichiro/vite-plugin-handlebars", + "version": "1.0.2", "author": { "name": "Yoichiro Tanaka", "email": "yoichiro6642@gmail.com", "url": "https://github.com/yoichiro" }, - "repository": "github:yoichiro/vite-plugin-handlebars-import", - "homepage": "https://github.com/yoichiro/vite-plugin-handlebars-import", + "repository": "github:yoichiro/vite-plugin-handlebars", + "homepage": "https://github.com/yoichiro/vite-plugin-handlebars", "bugs": { - "url": "https://github.com/yoichiro/vite-plugin-handlebars-import/issues" + "url": "https://github.com/yoichiro/vite-plugin-handlebars/issues" }, "dependencies": { "handlebars": "^4.7.8", diff --git a/src/index.ts b/src/index.ts index 16762e1..abeef9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,13 +6,13 @@ import { transform, } from './internal'; -export type HandlebarsImportPluginOptions = { +export type HandlebarsPluginOptions = { templateFileExtension?: string; partialsDirectoryPath?: string; }; -export default function handlebarsImportPlugin( - options: HandlebarsImportPluginOptions = {} +export default function handlebarsPlugin( + options: HandlebarsPluginOptions = {} ): Plugin { const templateFileExtension = decideTemplateFileExtension( options.templateFileExtension @@ -22,7 +22,7 @@ export default function handlebarsImportPlugin( options.partialsDirectoryPath ); return { - name: 'vite-plugin-handlebars-import', + name: '@yoichiro/vite-plugin-handlebars', transform(code, id) { if (!id.endsWith(templateFileExtension)) { return null; diff --git a/test/index.test.ts b/test/index.test.ts index d3ed5ee..e9c69ee 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,10 +1,10 @@ import { describe, expect, test } from 'vitest'; -import handlebarsImportPlugin from '../src'; +import handlebarsPlugin from '../src'; import path from 'path'; -describe('handlebarsImportPlugin', () => { +describe('handlebarsPlugin', () => { test('should return the plugin name', () => { - const plugin = handlebarsImportPlugin({ partialsDirectoryPath: '' }); - expect(plugin.name).toEqual('vite-plugin-handlebars-import'); + const plugin = handlebarsPlugin({ partialsDirectoryPath: '' }); + expect(plugin.name).toEqual('@yoichiro/vite-plugin-handlebars'); }); });