{"id":13605991,"url":"https://github.com/gedouu/vite-plugin-generate-html","last_synced_at":"2026-03-17T22:05:09.804Z","repository":{"id":63681225,"uuid":"569840371","full_name":"gedouu/vite-plugin-generate-html","owner":"gedouu","description":"This plugin allows you to define separate output files for JavaScript and CSS bundles. It generates \u003cscript\u003e and \u003clink\u003e elements from entry files and writes them to specified output files.","archived":false,"fork":false,"pushed_at":"2025-08-20T06:19:42.000Z","size":54,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-19T07:26:36.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/gedouu/vite-plugin-generate-html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gedouu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-23T18:27:00.000Z","updated_at":"2025-08-28T14:30:48.000Z","dependencies_parsed_at":"2024-11-07T10:34:57.143Z","dependency_job_id":"e7363a96-780b-4e9f-9b37-df4bacc23400","html_url":"https://github.com/gedouu/vite-plugin-generate-html","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":0.25,"last_synced_commit":"e7d344eb0c758da49585811653b96f384b0ad1e3"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/gedouu/vite-plugin-generate-html","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gedouu%2Fvite-plugin-generate-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gedouu%2Fvite-plugin-generate-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gedouu%2Fvite-plugin-generate-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gedouu%2Fvite-plugin-generate-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gedouu","download_url":"https://codeload.github.com/gedouu/vite-plugin-generate-html/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gedouu%2Fvite-plugin-generate-html/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30633240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:01:04.998Z","updated_at":"2026-03-17T22:05:09.799Z","avatar_url":"https://github.com/gedouu.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"readme":"# Vite Plugin Generate HTML\n\nThis plugin allows you to define separate output files for JavaScript and CSS bundles. It generates `\u003cscript\u003e` and `\u003clink\u003e` elements from entry files and writes them to specified output files.\n\nThis is particularly useful when:\n\n- Your bundles include a hash in the filename that changes with every compilation.\n- You have multiple views that need to include these JS and CSS bundles.\n- You want to output files in formats like `.html`, `.cshtml` (Razor), `.php`, etc.\n\nInspired by Webpack's `HtmlWebpackPlugin`, this plugin provides similar functionality for Vite.\n\n---\n\n## Installation\n\nInstall the plugin using npm:\n\n```bash\nnpm install --save-dev vite-plugin-generate-html\n```\n\n---\n\n## Parameters\n\nThe plugin accepts the following configuration options:\n\n```ts\n{\n  /**\n   * Directory to serve as plain static assets.\n   * @default \"/dist/\"\n   */\n  publicDir?: string;\n\n  /**\n   * The file to write the generated `\u003cscript\u003e` HTML to.\n   */\n  jsEntryFile: string;\n\n  /**\n   * The file to write the generated `\u003clink\u003e` HTML to.\n   */\n  cssEntryFile: string;\n\n  /**\n   * Custom attributes for `\u003cscript\u003e` and `\u003clink\u003e` elements for specific entry points.\n   *\n   * - Entry point names must match those defined in your Vite configuration.\n   * - If `output` is used, all entry points must be defined unless filtered using the `chunks` parameter.\n   * - Default attributes:\n   *   - `\u003cscript\u003e`: `['type=\"module\"']`\n   *   - `\u003clink\u003e`: `['rel=\"stylesheet\"', 'media=\"all\"']`\n   *\n   * @default []\n   * @example\n   * output: [\n   *   {\n   *     main: {\n   *       attrs: ['type=\"module\"', 'data-foo=\"bar\"'],\n   *       linkAttrs: ['rel=\"stylesheet\"', 'media=\"all\"']\n   *     }\n   *   }\n   * ]\n   */\n  output?: Array\u003c\n    Record\u003c\n      string,\n      {\n        /**\n         * Attributes for the generated `\u003cscript\u003e` element.\n         */\n        attrs: string[];\n\n        /**\n         * Attributes for the generated `\u003clink\u003e` element.\n         */\n        linkAttrs: string[];\n      }\n    \u003e\n  \u003e;\n\n  /**\n   * Limit the plugin to handle only specific entry points.\n   *\n   * - By default, all entry points are handled.\n   * - Use this to define different output paths for specific entries.\n   *\n   * @default []\n   * @example\n   * chunks: [\"app\", \"otherEntry\"]\n   */\n  chunks?: string[];\n}\n```\n\n---\n\n## Basic Usage\n\n### Step 1: Import CSS in Your Main Entry File\n\nEnsure your main entry file (e.g., `main.ts`) imports the required CSS:\n\n```js\nimport \"sass/styles.scss\";\n\n// Other entry-related code\nimport { createApp } from \"vue\";\n\nconst app = createApp({});\napp.mount(\"#app\");\n```\n\n### Step 2: Configure the Plugin in `vite.config.ts`\n\nAdd the plugin to your Vite configuration:\n\n```ts\n// vite.config.ts\nimport { resolve as pathResolve } from \"path\";\nimport { defineConfig } from \"vite\";\nimport VitePluginGenerateHtmlFiles from \"vite-plugin-generate-html\";\n\nexport default defineConfig({\n  build: {\n    rollupOptions: {\n      input: {\n        app: pathResolve(__dirname, \"src/main.ts\"),\n        // otherEntry: pathResolve(__dirname, \"src/other_entry.ts\")\n      },\n    },\n  },\n  plugins: [\n    VitePluginGenerateHtmlFiles({\n      publicDir: \"/dist/\",\n      jsEntryFile: pathResolve(__dirname, \"../some/dir/for/javascript.html\"),\n      cssEntryFile: pathResolve(__dirname, \"../some/dir/for/css.html\"),\n    }),\n    // Reuse the plugin for another entry with custom output options:\n    // VitePluginGenerateHtmlFiles({\n    //   publicDir: \"/dist/\",\n    //   jsEntryFile: pathResolve(__dirname, \"../some/dir/for/another-javascript.html\"),\n    //   cssEntryFile: pathResolve(__dirname, \"../some/dir/for/another-css.html\"),\n    //   output: [\n    //     {\n    //       otherEntry: {\n    //         attrs: ['type=\"module\"', 'data-foo=\"bar\"'],\n    //         linkAttrs: ['rel=\"stylesheet\"', 'media=\"all\"'],\n    //       },\n    //     },\n    //   ],\n    //   chunks: [\"otherEntry\"],\n    // }),\n  ],\n});\n```\n\n### Step 3: Generated Output\n\nAfter building your project, the plugin will generate the following files (paths may vary based on your configuration):\n\n#### `javascript.html`\n\n```html\n\u003cscript type=\"module\" src=\"/dist/app.[hash].js\"\u003e\u003c/script\u003e\n```\n\n#### `css.html`\n\n```html\n\u003clink href=\"/dist/main.[hash].css\" rel=\"stylesheet\" media=\"all\" /\u003e\n```\n\n\u003e **Note:** The plugin will overwrite the contents of the specified output files.\n\n---\n\n## Advanced Usage\n\n### Custom Attributes for Entry Points\n\nYou can define custom attributes for `\u003cscript\u003e` and `\u003clink\u003e` elements for specific entry points using the `output` parameter:\n\n```ts\noutput: [\n  {\n    main: {\n      attrs: ['type=\"module\"', 'data-foo=\"bar\"'],\n      linkAttrs: ['rel=\"stylesheet\"', 'media=\"all\"'],\n    },\n  },\n];\n```\n\n### Handling Specific Chunks\n\nUse the `chunks` parameter to limit the plugin to specific entry points:\n\n```ts\nchunks: [\"app\", \"otherEntry\"];\n```\n\nThis allows you to reuse the plugin for different entries with separate configurations.\n\n---\n\n## License\n\nThis project is licensed under the [MIT License](./LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgedouu%2Fvite-plugin-generate-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgedouu%2Fvite-plugin-generate-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgedouu%2Fvite-plugin-generate-html/lists"}