{"id":22170363,"url":"https://github.com/alessiogr/swc-plugin-strip-components","last_synced_at":"2025-10-08T07:50:59.381Z","repository":{"id":264498321,"uuid":"805891158","full_name":"AlessioGr/swc-plugin-strip-components","owner":"AlessioGr","description":"swc plugin to (almost) strip 'use client' components from code","archived":false,"fork":false,"pushed_at":"2024-05-26T18:15:57.000Z","size":4298,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-01T03:04:44.662Z","etag":null,"topics":["swc","swc-plugin"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/AlessioGr.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"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-05-25T19:01:28.000Z","updated_at":"2025-01-13T13:12:00.000Z","dependencies_parsed_at":"2024-11-24T18:43:15.175Z","dependency_job_id":null,"html_url":"https://github.com/AlessioGr/swc-plugin-strip-components","commit_stats":null,"previous_names":["alessiogr/swc-plugin-strip-components"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlessioGr/swc-plugin-strip-components","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlessioGr%2Fswc-plugin-strip-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlessioGr%2Fswc-plugin-strip-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlessioGr%2Fswc-plugin-strip-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlessioGr%2Fswc-plugin-strip-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlessioGr","download_url":"https://codeload.github.com/AlessioGr/swc-plugin-strip-components/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlessioGr%2Fswc-plugin-strip-components/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278909711,"owners_count":26066887,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["swc","swc-plugin"],"created_at":"2024-12-02T06:46:23.450Z","updated_at":"2025-10-08T07:50:59.362Z","avatar_url":"https://github.com/AlessioGr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swc-plugin-strip-components\n\nThis swc plugin can be used to do one (or both) of 2 things\n\n## 1. Lobotomize React 'use client' components in your code\n\nSometimes, you may have to import files which import client components on the server. This happens a lot of payload, where the payload config contains both server-side code, as well as client component imports.\n\nThis swc plugin automatically deletes the contents of files marked with 'use client' and keeps ONLY functions / variables which are exported. Additionally, those are nullified.\n\nThat way, code which relies on those imports will not break, and those client components are effectively \"disabled\".\n\nExample:\n\n**Input**\n\n```ts\n'use client'\n\nimport './index.scss' // Should be removed\nexport { MyFn as MyFnOtherFile } from \"../use client/ClientComponentInput\"; // should be kept, due to it being exported\nimport { MyFn as MyFnOtherFile2 } from \"../use client/ClientComponentOutput\"; // should be kept due to re-export below\nexport { MyFnOtherFile2 }  // should be kept, due to it being exported\nimport { MyFn2 as MyFn2FromAnotherFile } from \"../use client/ClientComponentInput\"; // should be removed. Not exported and not used anywhere\n\n\nimport { lazy } from 'react' // Should be removed\n\n\nconst RichTextEditor = lazy(() =\u003e\n    // @ts-ignore\n    import('../use client/ClientComponentOutput').then((module) =\u003e ({ default: module.MyFn })),\n) // Should be removed completely.\n\n\nconst MyFn = () =\u003e {\n    return \u003cdiv\u003eMyFn\u003c/div\u003e\n} // Should be kept due to exported below\n\nconst MyFn2 = () =\u003e {\n    return \u003cdiv\u003eMyFn2\u003c/div\u003e\n} // Should be kept due to exported below\n\nexport function MyFn4 () {\n    return \u003cdiv\u003eMyFn3\u003c/div\u003e\n} // Should be kept due to exported directly\n\n\nfunction MyFn5 () {\n    return \u003cdiv\u003eMyFn3\u003c/div\u003e\n} // Should be kept due to exported below\n\nfunction MyFn6 () { // Removed\n    return \u003cdiv\u003eMyFn3\u003c/div\u003e\n} // Should be removed completely. Not exported and not exported below\n\nexport const someVariable = 'someVariable' // Should be kept. Exported directly\n\nconst someVariable2 = 'someVariable2' // Should be kept. Exported below\n\nconst someVariable3 = 'someVariable3' // Should be removed\n\n\nexport { MyFn, MyFn2, MyFn5, someVariable2 }\n```\n\n**Output of this plugin:**\n```ts\n'use client';\nexport { MyFn as MyFnOtherFile } from \"../use client/ClientComponentInput\"; // should be kept, due to it being exported\nimport { MyFn as MyFnOtherFile2 } from \"../use client/ClientComponentOutput\"; // should be kept due to re-export below\nexport { MyFnOtherFile2 }; // should be kept, due to it being exported\nconst MyFn = ()=\u003enull// Should be kept due to exported below\n;\nconst MyFn2 = ()=\u003enull// Should be kept due to exported below\n;\nexport function MyFn4() {\n    return null;\n} // Should be kept due to exported directly\nfunction MyFn5() {\n    return null;\n} // Should be kept due to exported below\nexport const someVariable = null// Should be kept. Exported directly\n;\nconst someVariable2 = null// Should be kept. Exported below\n;\nexport { MyFn, MyFn2, MyFn5, someVariable2 };\n\n```\n\n## 2. Nullify arguments to a specified function\n\nThis can be useful if this plugin is conditionally enabled, and you only want components (or any code, really) to be available on the client-only (so, if this swc plugin is not enabled).\n\nIf the identifier in your swc config is set to Component, this will be the example input / output:\n\n**Input:**\n\n```ts\ntype Component = \u003cC\u003e(\n    C: C,\n) =\u003e C | null\n\nconst Component: Component = (c) =\u003e c as any\n\n{\n    someProp: Component(MyComponent)\n}\n```\n\n**Output:**\n\n```ts\ntype Component = \u003cC\u003e(\n    C: C,\n) =\u003e C | null\n\nconst Component: Component = (c) =\u003e c as any\n\n{\n    someProp: Component(null)\n}\n```\n\n\n\n\n## Installation\n\n```bash\npnpm add swc-plugin-strip-components\n```\n\nthen add it to your swc config:\n\n```ts\nconst modifiedConfig = {\n        ...swcRegisterConfig,\n        swc: {\n            ...{\n                ...swcRegisterConfig?.swc ?? {}\n            },\n            jsc: {\n                ...{\n                    ...swcRegisterConfig?.swc?.jsc ?? {}\n                },\n                experimental: {\n                    ...{\n                        ...swcRegisterConfig?.swc?.jsc?.experimental ?? {}\n                    },\n                    plugins: [\n                        ...swcRegisterConfig?.swc?.jsc?.experimental?.plugins ?? [],\n                        [\n                            'swc-plugin-strip-components',\n                            {\n                                identifier: 'Component', // the name of the function whose props should be nullified\n                                lobotomize_use_client_files: true\n                            }\n                        ]\n                    ]\n                }\n            }\n        }\n    };\n```\n\nOr in Next.js (if you want to break your entire app):\n\n```ts\nconst nextConfig = {\n  experimental: {\n    swcPlugins: [\n      [\n        \"swc-plugin-strip-components\",\n        {\n          identifier: 'Component',\n          lobotomize_use_client_files: false, // set to true, to break your entire next app\n        },\n      ],\n    ]\n  },\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiogr%2Fswc-plugin-strip-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falessiogr%2Fswc-plugin-strip-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiogr%2Fswc-plugin-strip-components/lists"}