{"id":25486999,"url":"https://github.com/eighty4/vite-plugin-html-inline-sources","last_synced_at":"2025-04-09T21:14:19.528Z","repository":{"id":268040442,"uuid":"903188841","full_name":"eighty4/vite-plugin-html-inline-sources","owner":"eighty4","description":"Inlining CSS and JS to improve web performance","archived":false,"fork":false,"pushed_at":"2025-02-11T15:02:19.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T21:13:53.829Z","etag":null,"topics":["css","esbuild","html","js","lightningcss","vite","web-performance"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eighty4.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2024-12-14T00:26:11.000Z","updated_at":"2025-02-11T15:02:23.000Z","dependencies_parsed_at":"2025-02-11T16:22:11.155Z","dependency_job_id":"e1ce8480-3f8f-4bc9-a929-ed6998ed74ed","html_url":"https://github.com/eighty4/vite-plugin-html-inline-sources","commit_stats":null,"previous_names":["eighty4/vite-plugin-html-inline-sources"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fvite-plugin-html-inline-sources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fvite-plugin-html-inline-sources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fvite-plugin-html-inline-sources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fvite-plugin-html-inline-sources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eighty4","download_url":"https://codeload.github.com/eighty4/vite-plugin-html-inline-sources/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111972,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["css","esbuild","html","js","lightningcss","vite","web-performance"],"created_at":"2025-02-18T19:34:31.303Z","updated_at":"2025-04-09T21:14:19.505Z","avatar_url":"https://github.com/eighty4.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-html-inline-sources\n\nA Vite plugin for inlining JS, CSS and SVG into `index.html` with a declarative `vite-inline` attribute.\n\n```html\n\u003c!-- CSS --\u003e\n\u003clink vite-inline rel=\"stylesheet\" href=\"index.css\"/\u003e\n\n\u003c!-- JavaScript --\u003e\n\u003cscript vite-inline type=\"module\" src=\"index.js\"\u003e\u003c/script\u003e\n\n\u003c!-- TypeScript --\u003e\n\u003cscript vite-inline type=\"module\" src=\"index.ts\"\u003e\u003c/script\u003e\n```\n\n## Why?\n\nPerformance gains from bundling JS and CSS sources in HTML are *extreme* and _visible_ to users immediately on page load.\n\nThis plugin should be used for code that applies custom theming, fonts, dark mode and CSS that curbs awkward\n[flash of unstyled content](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) \nbefore any network requests for CSS complete.\n\n### Alternative approaches\n\nThere are Vite plugins for inlining sources in HTML that focus on inlining *all* sources into a single file.\nPlugins that make HTML files without external dependencies are useful for embedded systems and\nmobile apps. Check out\n[vite-plugin-singlefile](https://www.npmjs.com/package/vite-plugin-singlefile) for those use cases.\n\n## Install\n\n```shell\npnpm i -D vite-plugin-html-inline-sources\n```\n\n## Usage\n\n### vite.config.js\n\n```js\nimport {defineConfig} from 'vite'\nimport inlining from 'vite-plugin-html-inline-sources'\n\nexport default defineConfig(() =\u003e {\n    return {\n        plugins: [inlining()]\n    }\n})\n```\n\n### index.html\n\n```html\n\u003chtml lang=\"en\"\u003e\n\u003cbody\u003e\n    \u003cscript vite-inline src=\"index.ts\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### `vite-inline` behaviors\n\n#### \u003cscript vite-inline src=\"index.js\"\u003e\n\nWithout `type=\"module\"` the script will be read from disk and inlined as-is.\n\n#### \u003cscript vite-inline src=\"index.js\" type=\"module\"\u003e\n\nJavaScript with `type=\"module\"` will use `esbuild.build` and bundle all imports in the script output and the script tag\nwill include the `type=\"module\"` attribute.\n\n#### \u003cscript vite-inline src=\"index.ts\"\u003e\n\nTypeScript inlining will use `esbuild.build` to bundle the script and any of its imports.\n\n_don't forget type=\"module\" if you use top-level-await or any other ESM module features_\n\n#### \u003clink vite-inline src=\"index.css\"\u003e\n\nCSS will be inlined as-is with a read of the file from your project directory.\n\nCurrently, nothing is done for `@import` within your CSS. Imported CSS could be bundled during inlining by using\n`lightningcss`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feighty4%2Fvite-plugin-html-inline-sources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feighty4%2Fvite-plugin-html-inline-sources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feighty4%2Fvite-plugin-html-inline-sources/lists"}