{"id":25254557,"url":"https://github.com/wspl/vite-static-component","last_synced_at":"2025-04-05T23:14:40.299Z","repository":{"id":83993182,"uuid":"576312878","full_name":"wspl/vite-static-component","owner":"wspl","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-10T09:28:13.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-12T05:42:18.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/wspl.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-12-09T14:28:19.000Z","updated_at":"2023-02-10T08:11:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"18b01ea4-855d-4ca1-8412-4886c6f32ebe","html_url":"https://github.com/wspl/vite-static-component","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wspl%2Fvite-static-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wspl%2Fvite-static-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wspl%2Fvite-static-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wspl%2Fvite-static-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wspl","download_url":"https://codeload.github.com/wspl/vite-static-component/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411238,"owners_count":20934654,"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":[],"created_at":"2025-02-12T05:32:29.651Z","updated_at":"2025-04-05T23:14:40.291Z","avatar_url":"https://github.com/wspl.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-static-component\nA Vite plugin that allows you to pre-render a subset of components in your project based on server-side rendering (SSR) technology. Using this plugin is simple and requires only a few easy configurations.\n\n## Installation\n\nTo install this plugin, run the following command:\n\n```sh\nnpm i -D vite-static-component\n```\n## Usage\n1. Add a mount anchor to an HTML file, such as `#static`\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003ctitle\u003eExample\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"app\"\u003e\u003c/div\u003e\n    \u003c!-- Add an anchor here --\u003e\n    \u003cdiv id=\"static\"\u003e\u003c/div\u003e\n    \u003cscript type=\"module\" src=\"/src/main.ts\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n2. Create a file named `static-entry.ts`\n```typescript\nimport { createSSRApp, createApp } from 'vue'\nimport Static from './Static.vue'\n\nexport function createStaticApp() {\n  // Currently, static generation is only used in production in order to reduce complexity in development.\n  if (import.meta.env.PROD) {\n    return createSSRApp(Static)\n  } else {\n    return createApp(Static)\n  }\n}\n\nexport function renderStatic() {\n  return createStaticApp().mount('#static')\n}\n```\nThis file is the entry point for your statically-rendered component, and it actually creates a new Vue SSR app.\n\n3. Then, in the entry point of your application, call the `renderStatic` function you just created.\n```typescript\nimport { createApp } from 'vue'\nimport App from './App.vue'\nimport { renderStatic } from './static-entry'\n\ncreateApp(App).mount('#app')\n\n// Call the render function (It actually performs the hydration work in SSR.)\nrenderStatic()\n```\n\n4. Finally, import this plugin in your vite.config.ts file and specify the entry point file you just created, as well as the selector for the anchor you added to the HTML file.\n```typescript\nimport { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport staticComponent from 'vite-static-component'\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    // Add and configure the plugin to vite.\n    staticComponent({\n      entry: 'src/static-entry.ts',\n      selector: '#static',\n    })\n  ],\n})\n```\n\n5. Now, you can build your project to see the resulting output.\n\n## License\nMIT License © 2022-PRESENT Plutonist Fu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwspl%2Fvite-static-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwspl%2Fvite-static-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwspl%2Fvite-static-component/lists"}