{"id":13417380,"url":"https://github.com/Applelo/vite-plugin-inject-preload","last_synced_at":"2025-03-15T02:31:14.096Z","repository":{"id":57714552,"uuid":"514937635","full_name":"Applelo/vite-plugin-inject-preload","owner":"Applelo","description":"A Vite plugin for injecting \u003clink rel='preload'\u003e ","archived":true,"fork":false,"pushed_at":"2023-09-04T15:52:56.000Z","size":628,"stargazers_count":18,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T22:38:37.086Z","etag":null,"topics":["preload","vite","vite-plugin","vitejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Applelo.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-07-17T19:32:52.000Z","updated_at":"2023-11-25T19:20:09.000Z","dependencies_parsed_at":"2024-06-19T02:47:35.730Z","dependency_job_id":"34b71c92-c2f0-46cb-a1db-35ee88cb2e68","html_url":"https://github.com/Applelo/vite-plugin-inject-preload","commit_stats":{"total_commits":47,"total_committers":1,"mean_commits":47.0,"dds":0.0,"last_synced_commit":"d74ed094655fd5e13f40b6fb1a5bed4475b0fec0"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Applelo%2Fvite-plugin-inject-preload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Applelo%2Fvite-plugin-inject-preload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Applelo%2Fvite-plugin-inject-preload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Applelo%2Fvite-plugin-inject-preload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Applelo","download_url":"https://codeload.github.com/Applelo/vite-plugin-inject-preload/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243674794,"owners_count":20329163,"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":["preload","vite","vite-plugin","vitejs"],"created_at":"2024-07-30T22:00:36.108Z","updated_at":"2025-03-15T02:31:13.790Z","avatar_url":"https://github.com/Applelo.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"readme":"\u003e This package [will not receive anymore update](https://github.com/Applelo/vite-plugin-inject-preload/issues/21). You can switch to [unplugin-inject-preload](https://github.com/Applelo/unplugin-inject-preload).\n\n[![npm](https://img.shields.io/npm/v/vite-plugin-inject-preload)](https://www.npmjs.com/package/vite-plugin-inject-preload) [![node-current](https://img.shields.io/node/v/vite-plugin-inject-preload)](https://nodejs.org/) [![Coverage Status](https://coveralls.io/repos/github/Applelo/vite-plugin-inject-preload/badge.svg?branch=main)](https://coveralls.io/github/Applelo/vite-plugin-inject-preload?branch=main)\n\n\n# vite-plugin-inject-preload\n\nA [Vite plugin](https://github.com/vitejs/vite) for injecting [\u0026lt;link rel='preload'\u003e](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content)\n\nThis plugin adds preload links on build by getting ViteJS output assets.\n\nSupporting Vite 3 and 4.\n\n \u003e Currently, this plugin **only works on build** because of [the way Vite behave](https://github.com/Applelo/vite-plugin-inject-preload/issues/15).\n\n## 📦 Install\n\n```\nnpm i -D vite-plugin-inject-preload\n\n# yarn\nyarn add -D vite-plugin-inject-preload\n\n# pnpm\npnpm add -D vite-plugin-inject-preload\n```\n\n## 👨‍💻 Usage\n\nAll the files needs to be process by ViteJS to be find by the plugin. For example, if I load this CSS file :\n\n```css\n@font-face {\n  font-family: 'Roboto';\n  src: url('./../fonts/Roboto-Italic.woff2');\n  font-weight: 400;\n  font-style: italic;\n}\n\n@font-face {\n  font-family: 'Roboto';\n  src: url('./../fonts/Roboto-Regular.woff2');\n  font-weight: 400;\n  font-style: normal;\n}\n```\n\nI can make the following configuration for VitePluginInjectPreload :\n\n```js\n// vite.config.js / vite.config.ts\nimport VitePluginInjectPreload from 'vite-plugin-inject-preload'\n\nexport default {\n  plugins: [\n    VitePluginInjectPreload({\n      files: [\n        {\n          match: /Roboto-[a-zA-Z]*-[a-z-0-9]*\\.woff2$/\n        },\n        {\n          match: /lazy.[a-z-0-9]*.(css|js)$/,\n        }\n      ]\n    })\n  ]\n}\n```\n\nFor the full example, check the demo folder available [here](https://github.com/Applelo/vite-plugin-inject-preload/tree/main/demo).\n\n### Options\n\n* files: An array of files object\n  * match: A regular expression to target build files you want to preload\n  * attributes (optional):\n  If this option is ommited, it will determine the `mime` and the `as` attributes automatically.\n  You can also add/override any attributes you want.\n* injectTo (optional): By default, the preload links are injected with the `'head-prepend'` options. But you can pass `'head'` to inject preload links at bottom of the head tag if you need it.\u003cbr\u003e Since 1.1, you can pass the `'custom'` option and put `\u003c!--__vite-plugin-inject-preload__--\u003e` in your `.html` file where you want to inject the preload links.\n\nWith the full options usage, you can do something like this :\n\n```js\n// vite.config.js / vite.config.ts\nimport VitePluginInjectPreload from 'vite-plugin-inject-preload'\n\nexport default {\n  plugins: [\n    VitePluginInjectPreload({\n      files: [\n        {\n          match: /Roboto-[a-zA-Z]*-[a-z-0-9]*\\.woff2$/,\n          attributes: {\n            'type': 'font/woff2',\n            'as': 'font',\n            'crossorigin': 'anonymous',\n            'data-font': 'Roboto'\n          }\n        },\n        {\n          match: /lazy.[a-z-0-9]*.(js)$/,\n          attributes: {\n            rel: 'modulepreload',\n            type: undefined,\n          }\n        }\n      ],\n      injectTo: 'head-prepend'\n    })\n  ]\n}\n```\n\n## 👨‍💼 Licence\n\nGPL-3.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FApplelo%2Fvite-plugin-inject-preload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FApplelo%2Fvite-plugin-inject-preload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FApplelo%2Fvite-plugin-inject-preload/lists"}