{"id":16367543,"url":"https://github.com/alexmacarthur/vite-plugin-proxy-page","last_synced_at":"2025-03-21T01:31:04.160Z","repository":{"id":60476714,"uuid":"534887869","full_name":"alexmacarthur/vite-plugin-proxy-page","owner":"alexmacarthur","description":"A Vite plugin for projecting your application onto a remote page during development.","archived":false,"fork":false,"pushed_at":"2023-06-09T15:53:09.000Z","size":42,"stargazers_count":28,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T02:50:12.753Z","etag":null,"topics":["local-development","proxy","spa","vite"],"latest_commit_sha":null,"homepage":"https://macarthur.me/posts/project-local-spa-onto-production-page","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/alexmacarthur.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}},"created_at":"2022-09-10T04:14:29.000Z","updated_at":"2024-04-16T22:59:27.000Z","dependencies_parsed_at":"2023-01-21T14:47:04.865Z","dependency_job_id":null,"html_url":"https://github.com/alexmacarthur/vite-plugin-proxy-page","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fvite-plugin-proxy-page","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fvite-plugin-proxy-page/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fvite-plugin-proxy-page/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fvite-plugin-proxy-page/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexmacarthur","download_url":"https://codeload.github.com/alexmacarthur/vite-plugin-proxy-page/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221810744,"owners_count":16884185,"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":["local-development","proxy","spa","vite"],"created_at":"2024-10-11T02:50:11.634Z","updated_at":"2024-10-28T08:59:38.975Z","avatar_url":"https://github.com/alexmacarthur.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-proxy-page\n\nA Vite plugin for developing an application in the context of a remote page.\n\n## What's the Problem?\n\nIt's an increasingly common pattern to independently develop small applications outside of the context in which they'll live. For example, an interactive calculator might be built with Vite's out-of-the-box development server, and then be published where it'll be used on the pages of an enterprise CMS -- pages that have their own set of styles, UI quirks, and other characteristics. If you're not careful, you could have unexpected interference with how your application looks or works.\n\nThis plugin swaps out your local `index.html` file for a public page of your choosing. You'll get the UI, styles, and other assets just as if you were on the actual page, but still get to keep the snappy developer experience of a typical Vite setup.\n\n## Installation\n\n`npm install vite-plugin-proxy-page`\n\n## Setup\n\nImport the plugin and initialize it your `plugins` array. To avoid issues with the [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react) and similar plugins that deal with JSX, make sure it's the **first** plugin registered in the array.\n\n```js\n// vite.config.js\n\nimport { proxyPage } from \"vite-plugin-proxy-page\";\n\nexport default defineConfig({\n  plugins: [\n    proxyPage({\n      // Options go here.\n    }),\n  ],\n  // ...remaining configuration\n});\n```\n\nAt the very least, you'll need to specify a remote page you'd like to proxy, as well as which local entry point Vite should inject onto the page. By default, this script tag will be injected just before the closing `\u003c/body\u003e` tag, but if that doesn't exist, it'll be attached to the end of the HTML.\n\n```diff\n// vite.config.js\n\nimport { proxyPage } from \"vite-plugin-proxy-page\";\n\nexport default defineConfig({\n  plugins: [\n    proxyPage({\n+     remoteUrl: \"https://vite-proxy-demo.netlify.app/some-page\",\n+     localEntryPoint: \"./local-dev.tsx\",\n    })\n  ],\n // ...remaining configuration\n});\n```\n\nAt this point, if your target page has a node to which you can mount and your `local-dev.tsx` file is targeting it, you're ready to go. However, if you want to inject a _new_ node onto a certain part of the page, you can use the `rootNode` options:\n\n```diff\n// vite.config.js\n\nimport { proxyPage } from \"vite-plugin-proxy-page\";\n\nexport default defineConfig({\n  plugins: [\n    proxyPage({\n      remoteUrl: \"https://vite-proxy-demo.netlify.app/some-page\",\n      localEntryPoint: \"./local-dev.tsx\",\n+     rootNode: {\n+       id: \"app\", // A `div` element with an ID of `app` will be added to the page.\n+       prependTo: \"main\" // Optional. If left empty, the body will be used.\n+     }\n    })\n  ],\n // ...remaining configuration\n});\n```\n\nUsing this example, a new `\u003cdiv id=\"app\"\u003e\u003c/div\u003e` node will be prepended to the `\u003cmain\u003e\u003c/main\u003e` element on the page.\n\n## Options\n\n| Name               | Description                                                                                                                                                                                                                                                                                                                                       | Required |\n| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |\n| `localEntryPoint`  | The entry point file that should be loaded onto the page. For a fresh Vite TypeScript project, this will be the `main.ts` file.                                                                                                                                                                                                                   | `true`   |\n| `remoteUrl`        | The full URL of the page you want proxy. Ex: \"https://example-site.com/my-page\"                                                                                                                                                                                                                                                                   | `true`   |\n| `remoteEntryPoint` | A RegExp or string of the deployed bundle URL. If this is set, the script tag loading that bundle will be removed from the proxied page's HTML in order to prevent unexpected bundle collisions with your local version. Ex: \"./production-bundle.js\" or /\\./production-bundle\\.js/                                                               | `false`  |\n| `rootNode`         | An object for specifying the HTML ID of the node you'd like to inject on to the page (`id`), as well as a CSS selector for where you'd like to prepend it (the default is the body). Use this if the remote page doesn't have a particular ID to which you'd like to mount your application. Ex: `{ id: \"myApp\", prependTo: \".ArticleContent\" }`. | `false`  |\n| `cacheHtml`        | Determines whether the remote HTML will be cached in memory while your Vite server runs, rather than refetching after each page reload or local code change. By default, this is set to `true`.                                                                                                                                                   | `false`  |\n## Contributions\n\nFile an issue or make a PR!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmacarthur%2Fvite-plugin-proxy-page","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexmacarthur%2Fvite-plugin-proxy-page","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmacarthur%2Fvite-plugin-proxy-page/lists"}