Extract cjsModuleRunnerPlugin from packages/plugin-rsc into a new standalone package @hiogawa/vite-plugin-cjs in a dedicated repository.
| Source File | Contents |
|---|---|
src/plugins/cjs.ts |
Main plugin cjsModuleRunnerPlugin(), extractPackageKey() |
src/transforms/cjs.ts |
Transform logic transformCjsToEsm() |
src/plugins/shared.ts |
Only parseIdQuery() function (~11 lines) |
@hiogawa/vite-plugin-cjs/
├── src/
│ ├── index.ts # Re-export plugin from plugin.ts
│ ├── plugin.ts # Main plugin (from plugins/cjs.ts)
│ ├── transform.ts # Transform logic (from transforms/cjs.ts)
│ └── utils.ts # parseIdQuery helper
├── package.json
├── tsconfig.json
└── tsdown.config.ts
package.json:
{
"name": "@hiogawa/vite-plugin-cjs",
"type": "module",
"exports": {
".": "./dist/index.js"
},
"files": ["dist"],
"peerDependencies": {
"vite": "*"
},
"dependencies": {
"@hiogawa/utils": "^1.7.0",
"es-module-lexer": "^2.0.0",
"estree-walker": "^3.0.3",
"magic-string": "^0.30.21",
"periscopic": "^4.0.2",
"vitefu": "^1.1.1"
}
}-
Add dependency:
"@hiogawa/vite-plugin-cjs": "^0.1.0" -
Update
src/plugins/cjs.tsto re-export:export { cjsModuleRunnerPlugin } from '@hiogawa/vite-plugin-cjs'
-
Remove
src/transforms/cjs.ts(no longer needed) -
Remove
parseIdQueryfromsrc/plugins/shared.tsif unused elsewhere
- Create new repo
vite-plugin-cjs - Initialize with package.json, tsconfig.json, tsdown config
- Copy and adapt source files:
plugin.ts- update importstransform.ts- no changes neededutils.ts- justparseIdQuery
- Create
index.tsentry point - Build and test locally
- Add
@hiogawa/vite-plugin-cjsas dependency - Replace
src/plugins/cjs.tswith re-export - Delete
src/transforms/cjs.ts - Check if
parseIdQueryis used elsewhere in shared.ts - Run tests to verify nothing broke
- The transform expects
__vite_ssr_exportAll__to exist at runtime (provided by Vite's module runner) - Plugin applies only when
env.config.dev.moduleRunnerTransformis enabled