vite-plugin-react-server 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -76
- package/bin/patch.mjs +27 -20
- package/dist/_virtual/dynamic-import-helper.js +24 -0
- package/dist/_virtual/dynamic-import-helper.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -26
- package/dist/index.js.map +1 -1
- package/dist/package.json +24 -14
- package/dist/plugin/components.d.ts +1 -1
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +18 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +42 -21
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getCondition.d.ts +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +2 -2
- package/dist/plugin/config/getCondition.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/index.d.ts +0 -1
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscover.js +128 -0
- package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +109 -77
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +0 -1
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +6 -8
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
- package/dist/plugin/config/resolveUrlOption.js +37 -0
- package/dist/plugin/config/resolveUrlOption.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -132
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy.d.ts +7 -0
- package/dist/plugin/copy.d.ts.map +1 -0
- package/dist/plugin/copy.js +30 -0
- package/dist/plugin/css-collector-elements.d.ts +4 -0
- package/dist/plugin/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/css-collector-elements.js +19 -0
- package/dist/plugin/css-collector-elements.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +2 -8
- package/dist/plugin/css-collector.d.ts.map +1 -1
- package/dist/plugin/css-collector.js +9 -36
- package/dist/plugin/css-collector.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts +3 -0
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
- package/dist/plugin/helpers/cleanObject.js +47 -0
- package/dist/plugin/helpers/cleanObject.js.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js +44 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
- package/dist/plugin/helpers/createCssProps.d.ts +25 -0
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
- package/dist/plugin/helpers/createCssProps.js +57 -0
- package/dist/plugin/helpers/createCssProps.js.map +1 -0
- package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createEventHandler.js +36 -0
- package/dist/plugin/helpers/createEventHandler.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +7 -13
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +54 -96
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +12 -26
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +105 -51
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
- package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
- package/dist/plugin/helpers/defaultFileWriter.js +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +30 -22
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.js +36 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +38 -32
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.d.ts +11 -0
- package/dist/plugin/helpers/metrics.d.ts.map +1 -0
- package/dist/plugin/helpers/metrics.js +35 -0
- package/dist/plugin/helpers/metrics.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +182 -0
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.js +14 -0
- package/dist/plugin/helpers/tryManifest.d.ts +5 -3
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +16 -7
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/html.d.ts +2 -3
- package/dist/plugin/html.d.ts.map +1 -1
- package/dist/plugin/html.js +7 -1
- package/dist/plugin/html.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +3 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +98 -33
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts +57 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.development.js +81 -0
- package/dist/plugin/loader/css-loader.development.js.map +1 -0
- package/dist/plugin/loader/css-loader.production.d.ts +31 -0
- package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.production.js +45 -0
- package/dist/plugin/loader/css-loader.production.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +2 -0
- package/dist/plugin/loader/index.d.ts.map +1 -0
- package/dist/plugin/loader/index.js +1 -0
- package/dist/plugin/loader/plugin.d.ts +22 -0
- package/dist/plugin/loader/plugin.d.ts.map +1 -0
- package/dist/plugin/loader/plugin.js +27 -0
- package/dist/plugin/loader/react-loader.d.ts +3 -7
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +85 -30
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
- package/dist/plugin/loader/temporaryReferences.js +11 -0
- package/dist/plugin/loader/temporaryReferences.js.map +1 -0
- package/dist/plugin/moduleRefs.d.ts +7 -0
- package/dist/plugin/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/moduleRefs.js +17 -0
- package/dist/plugin/moduleRefs.js.map +1 -0
- package/dist/plugin/plugin.client.d.ts +3 -0
- package/dist/plugin/plugin.client.d.ts.map +1 -0
- package/dist/plugin/plugin.client.js +19 -0
- package/dist/plugin/plugin.client.js.map +1 -0
- package/dist/plugin/plugin.d.ts +1 -5
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +3 -9
- package/dist/plugin/plugin.server.d.ts +3 -0
- package/dist/plugin/plugin.server.d.ts.map +1 -0
- package/dist/plugin/plugin.server.js +28 -0
- package/dist/plugin/plugin.server.js.map +1 -0
- package/dist/plugin/preserver/plugin.js +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +1 -2
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +1 -19
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +60 -219
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +27 -0
- package/dist/plugin/react-client/server.d.ts.map +1 -0
- package/dist/plugin/react-client/server.js +197 -0
- package/dist/plugin/react-client/server.js.map +1 -0
- package/dist/plugin/react-server/index.d.ts +1 -2
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +1 -21
- package/dist/plugin/react-server/plugin.d.ts +0 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +60 -186
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts +9 -0
- package/dist/plugin/react-server/server.d.ts.map +1 -0
- package/dist/plugin/react-server/server.js +120 -0
- package/dist/plugin/react-server/server.js.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
- package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectRscContent.js +49 -0
- package/dist/plugin/react-static/collectRscContent.js.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.js +67 -0
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
- package/dist/plugin/react-static/fileWriter.d.ts +23 -0
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
- package/dist/plugin/react-static/fileWriter.js +65 -0
- package/dist/plugin/react-static/fileWriter.js.map +1 -0
- package/dist/plugin/react-static/plugin.d.ts +15 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +248 -149
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +3 -0
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPage.js +116 -0
- package/dist/plugin/react-static/renderPage.js.map +1 -0
- package/dist/plugin/react-static/renderPages.d.ts +3 -0
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPages.js +125 -0
- package/dist/plugin/react-static/renderPages.js.map +1 -0
- package/dist/plugin/react-static/renderStreams.d.ts +26 -0
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
- package/dist/plugin/react-static/renderStreams.js +27 -0
- package/dist/plugin/react-static/renderStreams.js.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
- package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
- package/dist/plugin/react-static/streamHandler.d.ts +2 -0
- package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
- package/dist/plugin/react-static/streamHandler.js +1 -0
- package/dist/plugin/react-static/types.d.ts +11 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -1
- package/dist/plugin/resolvePage.d.ts +26 -9
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +41 -39
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/resolveProps.d.ts +40 -7
- package/dist/plugin/resolveProps.d.ts.map +1 -1
- package/dist/plugin/resolveProps.js +100 -75
- package/dist/plugin/resolveProps.js.map +1 -1
- package/dist/plugin/root.d.ts +1 -0
- package/dist/plugin/root.d.ts.map +1 -1
- package/dist/plugin/root.js +1 -0
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/index.d.ts +2 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +2 -1
- package/dist/plugin/transformer/plugin.client.d.ts +4 -0
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.client.js +83 -0
- package/dist/plugin/transformer/plugin.client.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts +1 -27
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +3 -87
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +4 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.server.js +76 -0
- package/dist/plugin/transformer/plugin.server.js.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
- package/dist/plugin/types/css-tracking.d.ts +6 -0
- package/dist/plugin/types/css-tracking.d.ts.map +1 -0
- package/dist/plugin/types/css-tracking.js +1 -0
- package/dist/plugin/types.d.ts +372 -86
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/vendor.client.d.ts +4 -0
- package/dist/plugin/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor.client.js +16 -0
- package/dist/plugin/vendor.client.js.map +1 -0
- package/dist/plugin/vendor.server.d.ts +4 -0
- package/dist/plugin/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor.server.js +16 -0
- package/dist/plugin/vendor.server.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +25 -7
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +108 -33
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +3 -17
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +12 -5
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +87 -84
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/types.d.ts +18 -0
- package/dist/plugin/worker/html/types.d.ts.map +1 -0
- package/dist/plugin/worker/html/types.js +1 -0
- package/dist/plugin/worker/registerLoaders.d.ts +9 -0
- package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
- package/dist/plugin/worker/registerLoaders.js +45 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/handleRender.js +147 -0
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +47 -112
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +73 -2
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +40 -3
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +3 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
- package/dist/plugin/worker/sendMessage.js +48 -0
- package/dist/plugin/worker/types.d.ts +218 -76
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/plugin/components.ts +1 -1
- package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
- package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
- package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
- package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
- package/plugin/config/defaults.tsx +38 -29
- package/plugin/config/getCondition.ts +7 -3
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/index.ts +0 -1
- package/plugin/config/resolveAutoDiscover.ts +177 -0
- package/plugin/config/resolveOptions.ts +220 -118
- package/plugin/config/resolvePages.ts +5 -7
- package/plugin/config/resolveUrlOption.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +116 -166
- package/plugin/copy.ts +39 -0
- package/plugin/css-collector-elements.tsx +21 -0
- package/plugin/css-collector.tsx +20 -53
- package/plugin/helpers/cleanObject.ts +50 -0
- package/plugin/helpers/collectBundleManifestCss.ts +160 -0
- package/plugin/helpers/collectManifestCss.ts +61 -0
- package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
- package/plugin/helpers/createCssProps.tsx +85 -0
- package/plugin/helpers/createEventHandler.ts +44 -0
- package/plugin/helpers/createHandler.ts +57 -126
- package/plugin/helpers/createRscStream.tsx +156 -0
- package/plugin/helpers/defaultFileWriter.ts +0 -0
- package/plugin/helpers/getBundleManifest.ts +42 -37
- package/plugin/helpers/getRouteFiles.ts +47 -0
- package/plugin/helpers/inputNormalizer.ts +16 -10
- package/plugin/helpers/metrics.ts +64 -0
- package/plugin/helpers/resolvePageAndProps.ts +81 -0
- package/plugin/helpers/serializeUserOptions.ts +209 -0
- package/plugin/helpers/stashReturnValue.ts +16 -0
- package/plugin/helpers/tryManifest.ts +35 -18
- package/plugin/html.tsx +14 -3
- package/plugin/index.ts +5 -2
- package/plugin/loader/createBuildLoader.ts +152 -47
- package/plugin/loader/css-loader.development.ts +157 -0
- package/plugin/loader/css-loader.production.ts +86 -0
- package/plugin/loader/index.ts +1 -0
- package/plugin/loader/plugin.ts +33 -0
- package/plugin/loader/react-loader.ts +109 -41
- package/plugin/loader/temporaryReferences.ts +3 -0
- package/plugin/moduleRefs.ts +11 -0
- package/plugin/plugin.client.ts +12 -0
- package/plugin/plugin.server.ts +25 -0
- package/plugin/plugin.ts +5 -9
- package/plugin/preserver/plugin.ts +1 -1
- package/plugin/react-client/index.ts +1 -12
- package/plugin/react-client/plugin.ts +70 -259
- package/plugin/react-client/server.ts +276 -0
- package/plugin/react-server/index.ts +1 -14
- package/plugin/react-server/plugin.ts +69 -220
- package/plugin/react-server/server.ts +128 -0
- package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
- package/plugin/react-static/collectRscContent.ts +77 -0
- package/plugin/react-static/configurePreviewServer.ts +68 -0
- package/plugin/react-static/fileWriter.ts +103 -0
- package/plugin/react-static/plugin.ts +308 -181
- package/plugin/react-static/renderPage.ts +151 -0
- package/plugin/react-static/renderPages.ts +154 -0
- package/plugin/react-static/renderStreams.ts +48 -0
- package/plugin/react-static/rscToHtmlStream.ts +85 -0
- package/plugin/react-static/streamHandler.ts +0 -0
- package/plugin/react-static/types.ts +10 -0
- package/plugin/resolvePage.ts +67 -57
- package/plugin/resolveProps.ts +148 -104
- package/plugin/root.ts +1 -1
- package/plugin/transformer/index.ts +2 -1
- package/plugin/transformer/plugin.client.ts +109 -0
- package/plugin/transformer/plugin.server.ts +98 -0
- package/plugin/transformer/plugin.ts +2 -115
- package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
- package/plugin/types/css-tracking.ts +5 -0
- package/plugin/types/react-server-dom-esm.d.ts +54 -0
- package/plugin/types.ts +508 -97
- package/plugin/vendor.client.ts +12 -0
- package/plugin/vendor.server.ts +12 -0
- package/plugin/worker/createWorker.ts +158 -53
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
- package/plugin/worker/html/html-worker.development.tsx +5 -75
- package/plugin/worker/html/html-worker.production.tsx +18 -7
- package/plugin/worker/html/messageHandler.tsx +126 -0
- package/plugin/worker/html/types.ts +19 -0
- package/plugin/worker/registerLoaders.ts +54 -0
- package/plugin/worker/rsc/handleRender.ts +180 -0
- package/plugin/worker/rsc/messageHandler.tsx +58 -132
- package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
- package/plugin/worker/rsc/state.ts +79 -2
- package/plugin/worker/sendMessage.ts +49 -0
- package/plugin/worker/types.ts +299 -100
- package/scripts/check-react-version.mjs +60 -48
- package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
- package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
- package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
- package/tsconfig.json +7 -2
- package/dist/plugin/assertServerCondition.d.ts +0 -6
- package/dist/plugin/assertServerCondition.d.ts.map +0 -1
- package/dist/plugin/assertServerCondition.js +0 -13
- package/dist/plugin/checkFilesExist.d.ts +0 -3
- package/dist/plugin/checkFilesExist.d.ts.map +0 -1
- package/dist/plugin/checkFilesExist.js +0 -67
- package/dist/plugin/checkFilesExist.js.map +0 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
- package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
- package/dist/plugin/collect-manifest-client-files.js +0 -131
- package/dist/plugin/collect-manifest-client-files.js.map +0 -1
- package/dist/plugin/config/getWorkerPath.d.ts +0 -2
- package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
- package/dist/plugin/config/getWorkerPath.js +0 -4
- package/dist/plugin/copy-dir.d.ts +0 -4
- package/dist/plugin/copy-dir.d.ts.map +0 -1
- package/dist/plugin/copy-dir.js +0 -25
- package/dist/plugin/copy-dir.js.map +0 -1
- package/dist/plugin/css-collector-inline.d.ts +0 -10
- package/dist/plugin/css-collector-inline.d.ts.map +0 -1
- package/dist/plugin/css-collector-inline.js +0 -55
- package/dist/plugin/css-collector-inline.js.map +0 -1
- package/dist/plugin/loader/css-loader.d.ts +0 -16
- package/dist/plugin/loader/css-loader.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.js +0 -70
- package/dist/plugin/loader/css-loader.js.map +0 -1
- package/dist/plugin/react-client/index.js.map +0 -1
- package/dist/plugin/react-server/index.js.map +0 -1
- package/dist/plugin/worker/html/renderPages.d.ts +0 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
- package/dist/plugin/worker/html/renderPages.js +0 -241
- package/dist/plugin/worker/html/renderPages.js.map +0 -1
- package/plugin/assertServerCondition.ts +0 -12
- package/plugin/checkFilesExist.ts +0 -66
- package/plugin/collect-manifest-client-files.ts +0 -167
- package/plugin/config/getWorkerPath.ts +0 -5
- package/plugin/copy-dir.ts +0 -27
- package/plugin/css-collector-inline.tsx +0 -60
- package/plugin/helpers/createRscStream.ts +0 -109
- package/plugin/loader/css-loader.ts +0 -94
- package/plugin/worker/html/messageHandler.ts +0 -130
- package/plugin/worker/html/renderPages.ts +0 -293
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
package/plugin/resolveProps.ts
CHANGED
|
@@ -1,131 +1,175 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exportName: string;
|
|
1
|
+
|
|
2
|
+
type ResolvePropsOptions<N extends string> = {
|
|
3
|
+
id: string;
|
|
5
4
|
url: string;
|
|
5
|
+
exportName: N;
|
|
6
|
+
loader: (id: string) => Promise<any>;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
|
-
type ResolvePropsResult =
|
|
9
|
-
| { type: "success"; key: string; props:
|
|
9
|
+
type ResolvePropsResult<T, N extends string> =
|
|
10
|
+
| { type: "success"; key: string; props: T; module?: { [key in N]: T } }
|
|
10
11
|
| { type: "error"; error: Error }
|
|
11
12
|
| { type: "skip" };
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Resolves props from a module, handling both real and virtual modules.
|
|
16
|
+
*
|
|
17
|
+
* During development (ssrLoadModule):
|
|
18
|
+
* - Real modules have exports available directly on the module object
|
|
19
|
+
* - Virtual modules have exports stored in temporaryReferences
|
|
20
|
+
*
|
|
21
|
+
* During build (createBuildLoader):
|
|
22
|
+
* - Transformed modules (with ast/code) have exports as direct properties
|
|
23
|
+
* - The exports array contains just the names of those exports
|
|
24
|
+
* - We store the module in temporaryReferences for later use
|
|
25
|
+
* - We access exports directly from the module object
|
|
26
|
+
*
|
|
27
|
+
* Props can be:
|
|
28
|
+
* 1. A function that takes a URL and returns props
|
|
29
|
+
* 2. A direct object of props
|
|
30
|
+
* 3. A renamed export (where the actual export name differs from the expected name)
|
|
31
|
+
*
|
|
32
|
+
* @param options.propsModule - The module object from ssrLoadModule or createBuildLoader
|
|
33
|
+
* @param options.path - The normalized path to the module
|
|
34
|
+
* @param options.url - The URL route this page handles
|
|
35
|
+
* @param options.exportName - The name of the export to resolve (e.g. 'props')
|
|
36
|
+
* @param options.temporaryReferences - WeakMap used to store and retrieve virtual module references
|
|
37
|
+
*
|
|
38
|
+
* @returns A result object containing:
|
|
39
|
+
* - type: "success" | "error" | "skip"
|
|
40
|
+
* - key: The export name if successful
|
|
41
|
+
* - props: The resolved props if successful
|
|
42
|
+
* - error: Error message if failed
|
|
43
|
+
*/
|
|
44
|
+
export const resolveProps = async <T, N extends string>({
|
|
45
|
+
id,
|
|
21
46
|
url,
|
|
22
|
-
|
|
23
|
-
|
|
47
|
+
exportName,
|
|
48
|
+
loader,
|
|
49
|
+
}: ResolvePropsOptions<N>): Promise<ResolvePropsResult<T, N>> => {
|
|
50
|
+
// Check if this is a stashed page that needs special handling
|
|
51
|
+
const propsLoadResult = await (async (): Promise<
|
|
52
|
+
| { type: "success"; key: string; module: { [key in N]: T } }
|
|
53
|
+
| { type: "error"; error: Error; module?: never }
|
|
54
|
+
> => {
|
|
55
|
+
try {
|
|
56
|
+
return {
|
|
57
|
+
type: "success",
|
|
58
|
+
key: id,
|
|
59
|
+
module: await loader(id),
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
type: "error",
|
|
64
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
|
|
69
|
+
if (propsLoadResult.type !== "success") {
|
|
70
|
+
return propsLoadResult;
|
|
71
|
+
}
|
|
72
|
+
const { module } = propsLoadResult;
|
|
73
|
+
const props = module[exportName as N];
|
|
74
|
+
// handle different props use-cases
|
|
75
|
+
if (module instanceof Error) {
|
|
24
76
|
return {
|
|
25
77
|
type: "error",
|
|
26
|
-
error:
|
|
78
|
+
error: module,
|
|
27
79
|
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
80
|
+
} else if (!(exportName in module)) {
|
|
81
|
+
return {
|
|
82
|
+
type: "success",
|
|
83
|
+
key: exportName,
|
|
84
|
+
props: { url, ...module } as T,
|
|
85
|
+
module,
|
|
86
|
+
};
|
|
87
|
+
} else if (!props) {
|
|
88
|
+
return {
|
|
89
|
+
type: "success",
|
|
90
|
+
key: exportName,
|
|
91
|
+
props: { url } as T,
|
|
92
|
+
module: module as { [key in N]: T },
|
|
93
|
+
};
|
|
94
|
+
} else if (props instanceof Error) {
|
|
31
95
|
return {
|
|
32
96
|
type: "error",
|
|
33
|
-
error:
|
|
34
|
-
`propsModule must be an object, got ${typeof propsModule}`
|
|
35
|
-
),
|
|
97
|
+
error: props,
|
|
36
98
|
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const keys = Object.keys(propsModule);
|
|
40
|
-
let found = keys.find((v) => v === exportName || v === url || v === path);
|
|
41
|
-
if(exportName in propsModule) {
|
|
42
|
-
found = exportName;
|
|
43
|
-
}
|
|
44
|
-
if (found) {
|
|
45
|
-
let value = propsModule[found];
|
|
99
|
+
} else if (typeof props === "function") {
|
|
100
|
+
// Handle both class constructors and regular functions
|
|
46
101
|
try {
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
102
|
+
let propsResult;
|
|
103
|
+
if (props.prototype && props.prototype.constructor) {
|
|
104
|
+
// Class constructor case
|
|
105
|
+
propsResult = new (props as new (url: string) => T)(url);
|
|
106
|
+
} else {
|
|
107
|
+
// Regular function case
|
|
108
|
+
propsResult = props(url);
|
|
55
109
|
}
|
|
56
|
-
|
|
57
|
-
// If it's a promise, await it
|
|
58
|
-
if (value && typeof value.then === "function") {
|
|
59
|
-
const props = await value;
|
|
60
|
-
return {
|
|
61
|
-
type: "success",
|
|
62
|
-
key: found,
|
|
63
|
-
props,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// If it's a plain object, use it directly
|
|
68
|
-
if (typeof value === "object" && value !== null) {
|
|
69
|
-
return {
|
|
70
|
-
type: "success",
|
|
71
|
-
key: found,
|
|
72
|
-
props: value,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
110
|
|
|
111
|
+
return {
|
|
112
|
+
type: "success",
|
|
113
|
+
key: exportName,
|
|
114
|
+
props: propsResult instanceof Promise ? await propsResult : propsResult,
|
|
115
|
+
module: module as { [key in N]: T },
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
77
118
|
return {
|
|
78
119
|
type: "error",
|
|
79
|
-
error: new Error(
|
|
80
|
-
|
|
81
|
-
|
|
120
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
} else if (props instanceof Promise) {
|
|
124
|
+
// object case
|
|
125
|
+
try {
|
|
126
|
+
return {
|
|
127
|
+
type: "success",
|
|
128
|
+
key: exportName,
|
|
129
|
+
props: await props,
|
|
130
|
+
module: propsLoadResult.module,
|
|
82
131
|
};
|
|
83
132
|
} catch (error) {
|
|
84
|
-
console.trace(error);
|
|
85
|
-
console.warn(found, "error in resolveProps", propsModule, url, path);
|
|
86
133
|
return {
|
|
87
134
|
type: "error",
|
|
88
|
-
error: error
|
|
135
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
} else if (Array.isArray(props)) {
|
|
139
|
+
// array case
|
|
140
|
+
try {
|
|
141
|
+
return {
|
|
142
|
+
type: "success",
|
|
143
|
+
key: exportName,
|
|
144
|
+
props: Object.fromEntries(
|
|
145
|
+
props.map((prop) => (typeof prop === "string" ? [prop, prop] : prop))
|
|
146
|
+
) as T,
|
|
147
|
+
module: propsLoadResult.module,
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return {
|
|
151
|
+
type: "error",
|
|
152
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
} else if (typeof props === "string") {
|
|
156
|
+
try {
|
|
157
|
+
return {
|
|
158
|
+
type: "success",
|
|
159
|
+
key: exportName,
|
|
160
|
+
props: JSON.parse(props),
|
|
161
|
+
};
|
|
162
|
+
} catch (error) {
|
|
163
|
+
return {
|
|
164
|
+
type: "error",
|
|
165
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
89
166
|
};
|
|
90
167
|
}
|
|
91
168
|
}
|
|
92
|
-
const commonjs = keys.find((v) => v === "exports");
|
|
93
|
-
|
|
94
|
-
if (!!commonjs) {
|
|
95
|
-
const exportKeys = (commonjs as unknown as { exports: any })["exports"]
|
|
96
|
-
? Object.keys((commonjs as unknown as { exports: any })["exports"])
|
|
97
|
-
: [];
|
|
98
|
-
const foundCommonJS = exportKeys.find(
|
|
99
|
-
(v) => v === exportName || v === url || v === path
|
|
100
|
-
);
|
|
101
|
-
return {
|
|
102
|
-
type: "error",
|
|
103
|
-
error: new Error(
|
|
104
|
-
`Expected props export "${exportName}" in "${path}", but instead got "exports" with ${
|
|
105
|
-
!!foundCommonJS
|
|
106
|
-
? foundCommonJS.toString()
|
|
107
|
-
: exportKeys.length
|
|
108
|
-
? exportKeys.join(", ")
|
|
109
|
-
: "no keys"
|
|
110
|
-
}, this will not work. Make sure to set esModule: true in rollupOptions.output. ${JSON.stringify(propsModule)}`
|
|
111
|
-
),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
if (Object.keys(propsModule).includes("error")) {
|
|
115
|
-
return {
|
|
116
|
-
type: "error",
|
|
117
|
-
error: propsModule["error"],
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
169
|
return {
|
|
122
|
-
type: "
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
? "Available exports: " + keys.join(", ")
|
|
127
|
-
: "The object was defined but has no properties. \"" + JSON.stringify(propsModule) + "\""
|
|
128
|
-
}`
|
|
129
|
-
),
|
|
170
|
+
type: "success",
|
|
171
|
+
key: exportName,
|
|
172
|
+
props: props,
|
|
173
|
+
module: module as { [key in N]: T },
|
|
130
174
|
};
|
|
131
|
-
}
|
|
175
|
+
};
|
package/plugin/root.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { reactTransformPlugin } from "./plugin.js";
|
|
1
|
+
export { reactTransformPlugin as reactTransformPluginServer } from "./plugin.server.js";
|
|
2
|
+
export { reactTransformPlugin as reactTransformPluginClient } from "./plugin.client.js";
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { resolveOptions } from "../config/resolveOptions.js";
|
|
2
|
+
import type { ResolvedUserOptions, StreamPluginOptions } from "../types.js";
|
|
3
|
+
import { type Manifest, type Plugin } from "vite";
|
|
4
|
+
import { transformModuleIfNeeded } from "../loader/react-loader.js";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { tryManifest } from "../helpers/tryManifest.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Plugin for transforming server actions for the client build.
|
|
10
|
+
*
|
|
11
|
+
* Core responsibilities:
|
|
12
|
+
* 1. Transforms "use server" directives
|
|
13
|
+
* 2. Transforms server actions for the client build
|
|
14
|
+
* 3. Uses react-loader's transformModuleIfNeeded to create a server action reference
|
|
15
|
+
*
|
|
16
|
+
* When a component is marked with "use server", it:
|
|
17
|
+
* - Gets transformed into a server action
|
|
18
|
+
* - Maintains module ID for RSC boundaries
|
|
19
|
+
* - Preserves class/function behavior
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* export default defineConfig({
|
|
24
|
+
* plugins: [
|
|
25
|
+
* viteReactClientTransformPlugin({
|
|
26
|
+
* projectRoot: process.cwd(),
|
|
27
|
+
* })
|
|
28
|
+
* ]
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
let isBuild = true;
|
|
33
|
+
|
|
34
|
+
export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
35
|
+
let userOptions: ResolvedUserOptions;
|
|
36
|
+
const resolvedOptionsResult = resolveOptions(options);
|
|
37
|
+
if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
|
|
38
|
+
userOptions = resolvedOptionsResult.userOptions;
|
|
39
|
+
let staticManifest: Manifest;
|
|
40
|
+
return {
|
|
41
|
+
name: "vite:react-server-action-transform",
|
|
42
|
+
enforce: "pre",
|
|
43
|
+
async config(_, configEnv) {
|
|
44
|
+
isBuild = configEnv.command !== "serve";
|
|
45
|
+
if (!configEnv.isSsrBuild) {
|
|
46
|
+
staticManifest = {};
|
|
47
|
+
} else {
|
|
48
|
+
const staticManifestResult = await tryManifest({
|
|
49
|
+
root: userOptions.projectRoot,
|
|
50
|
+
ssrManifest: false,
|
|
51
|
+
outDir: join(userOptions.build.outDir, userOptions.build.static),
|
|
52
|
+
});
|
|
53
|
+
if (staticManifestResult.type === "error") {
|
|
54
|
+
staticManifest = {};
|
|
55
|
+
} else {
|
|
56
|
+
staticManifest = staticManifestResult.manifest;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async transform(code, id, options) {
|
|
61
|
+
const ssr = options?.ssr;
|
|
62
|
+
const isServer = code.match('"use server"') !== null;
|
|
63
|
+
const isClient = code.match('"use client"') !== null;
|
|
64
|
+
if (!ssr) return null;
|
|
65
|
+
if (!isServer && !isClient) return null;
|
|
66
|
+
if (isServer && isClient) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"Server and client components cannot be used in the same file"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (isClient) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (isServer && isBuild) {
|
|
75
|
+
const [key] = userOptions.normalizer(id);
|
|
76
|
+
id = "/" + key + ".js";
|
|
77
|
+
}
|
|
78
|
+
const transformed = await transformModuleIfNeeded(code, id, null);
|
|
79
|
+
if (!transformed) return null;
|
|
80
|
+
return {
|
|
81
|
+
code: transformed,
|
|
82
|
+
id: id,
|
|
83
|
+
map: null,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
renderChunk(code, chunk, _options) {
|
|
87
|
+
// Only process client components
|
|
88
|
+
if (!chunk.fileName.includes(".client")) return null;
|
|
89
|
+
|
|
90
|
+
// Get the original file name without extension
|
|
91
|
+
const originalName = chunk.fileName.replace(".js", "");
|
|
92
|
+
|
|
93
|
+
// Find matching entry in static manifest
|
|
94
|
+
const manifestEntry = Object.entries(staticManifest).find(([_, info]) =>
|
|
95
|
+
info.file.startsWith(originalName)
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (manifestEntry) {
|
|
99
|
+
// Use the static manifest's file name
|
|
100
|
+
return {
|
|
101
|
+
code,
|
|
102
|
+
fileName: manifestEntry[1].file,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return null;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { resolveOptions } from "../config/resolveOptions.js";
|
|
2
|
+
import type { ResolvedUserOptions, StreamPluginOptions } from "../types.js";
|
|
3
|
+
import type { Manifest, Plugin } from "vite";
|
|
4
|
+
import { transformModuleIfNeeded } from "../loader/react-loader.js";
|
|
5
|
+
import { tryManifest } from "../helpers/tryManifest.js";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
/**
|
|
8
|
+
* Plugin for transforming React Client Components.
|
|
9
|
+
*
|
|
10
|
+
* Core responsibilities:
|
|
11
|
+
* 1. Detects "use client" directives
|
|
12
|
+
* 2. Transforms client components for RSC boundaries
|
|
13
|
+
* 3. Adds client reference metadata for RSC
|
|
14
|
+
*
|
|
15
|
+
* When a component is marked with "use client", it:
|
|
16
|
+
* - Gets transformed into a client reference
|
|
17
|
+
* - Maintains module ID for RSC boundaries
|
|
18
|
+
* - Preserves class/function behavior
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* plugins: [
|
|
24
|
+
* viteReactClientTransformPlugin({
|
|
25
|
+
* projectRoot: process.cwd(),
|
|
26
|
+
* })
|
|
27
|
+
* ]
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
let isBuild = true;
|
|
32
|
+
|
|
33
|
+
export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
34
|
+
let userOptions: ResolvedUserOptions;
|
|
35
|
+
const resolvedOptionsResult = resolveOptions(options);
|
|
36
|
+
if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
|
|
37
|
+
userOptions = resolvedOptionsResult.userOptions;
|
|
38
|
+
|
|
39
|
+
let staticManifest: Manifest;
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
name: "vite:react-server-transform",
|
|
43
|
+
enforce: "pre", // Run before Vite's transforms
|
|
44
|
+
async config(_, configEnv) {
|
|
45
|
+
isBuild = configEnv.command !== "serve";
|
|
46
|
+
const staticManifestResult = await tryManifest({
|
|
47
|
+
root: userOptions.projectRoot,
|
|
48
|
+
ssrManifest: false,
|
|
49
|
+
outDir: join(userOptions.build.outDir, userOptions.build.static),
|
|
50
|
+
});
|
|
51
|
+
if (staticManifestResult.type === "error") {
|
|
52
|
+
console.error(staticManifestResult.error);
|
|
53
|
+
throw staticManifestResult.error;
|
|
54
|
+
}
|
|
55
|
+
staticManifest = staticManifestResult.manifest;
|
|
56
|
+
},
|
|
57
|
+
async transform(code, id, options) {
|
|
58
|
+
const ssr = options?.ssr;
|
|
59
|
+
if (!ssr) return null;
|
|
60
|
+
if (!userOptions.autoDiscover.modulePattern(id)) return null;
|
|
61
|
+
if (!code.match('"use client"')) return null;
|
|
62
|
+
|
|
63
|
+
if (isBuild) {
|
|
64
|
+
const [key, value] = userOptions.normalizer(id);
|
|
65
|
+
if (staticManifest) {
|
|
66
|
+
if (value in staticManifest) {
|
|
67
|
+
id = '/' + staticManifest[value].file;
|
|
68
|
+
} else {
|
|
69
|
+
const hash = this.emitFile({
|
|
70
|
+
id,
|
|
71
|
+
type: "chunk",
|
|
72
|
+
fileName: key + ".js",
|
|
73
|
+
name: value,
|
|
74
|
+
});
|
|
75
|
+
// get fileName from hash
|
|
76
|
+
|
|
77
|
+
const fileName = this.getFileName(hash);
|
|
78
|
+
id = '/' + fileName;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error(`Client manifest not found.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const transformed = await transformModuleIfNeeded(
|
|
85
|
+
code,
|
|
86
|
+
id,
|
|
87
|
+
// Pass null for nextLoad since we don't need module loading in the plugin
|
|
88
|
+
null
|
|
89
|
+
);
|
|
90
|
+
if (!transformed) return null;
|
|
91
|
+
return {
|
|
92
|
+
code: transformed,
|
|
93
|
+
id: id,
|
|
94
|
+
map: null,
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -1,116 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { InputNormalizer, ResolvedUserOptions, StreamPluginOptions } from "../types.js";
|
|
3
|
-
import { type Manifest, type Plugin } from "vite";
|
|
4
|
-
import { transformModuleIfNeeded } from "../loader/react-loader.js";
|
|
5
|
-
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
6
|
-
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
7
|
-
import { tryManifest } from "../helpers/tryManifest.js";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
/**
|
|
10
|
-
* Plugin for transforming React Client Components.
|
|
11
|
-
*
|
|
12
|
-
* Core responsibilities:
|
|
13
|
-
* 1. Detects "use client" directives
|
|
14
|
-
* 2. Transforms client components for RSC boundaries
|
|
15
|
-
* 3. Adds client reference metadata for RSC
|
|
16
|
-
*
|
|
17
|
-
* When a component is marked with "use client", it:
|
|
18
|
-
* - Gets transformed into a client reference
|
|
19
|
-
* - Maintains module ID for RSC boundaries
|
|
20
|
-
* - Preserves class/function behavior
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* export default defineConfig({
|
|
25
|
-
* plugins: [
|
|
26
|
-
* viteReactClientTransformPlugin({
|
|
27
|
-
* projectRoot: process.cwd(),
|
|
28
|
-
* })
|
|
29
|
-
* ]
|
|
30
|
-
* });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
1
|
+
import { getCondition } from '../config/getCondition.js';
|
|
33
2
|
|
|
34
|
-
export
|
|
35
|
-
let normalizer: InputNormalizer;
|
|
36
|
-
let clientManifest: Manifest;
|
|
37
|
-
let isDev:boolean;
|
|
38
|
-
let userOptions: ResolvedUserOptions
|
|
39
|
-
return {
|
|
40
|
-
name: "vite:react-transform",
|
|
41
|
-
enforce: "pre", // Run before Vite's transforms
|
|
42
|
-
config(config, configEnv) {
|
|
43
|
-
const resolvedOptionsResult = resolveOptions(
|
|
44
|
-
options,
|
|
45
|
-
config.build?.outDir?.startsWith(
|
|
46
|
-
join(options.build?.outDir ?? DEFAULT_CONFIG.BUILD.outDir, options.build?.client ?? DEFAULT_CONFIG.BUILD.client)
|
|
47
|
-
) ?? false
|
|
48
|
-
);
|
|
49
|
-
isDev = configEnv.mode === "development" && configEnv.command === "serve"
|
|
50
|
-
if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
|
|
51
|
-
userOptions = resolvedOptionsResult.userOptions;
|
|
52
|
-
normalizer = createInputNormalizer({
|
|
53
|
-
root: resolvedOptionsResult.userOptions.projectRoot,
|
|
54
|
-
preserveModulesRoot: undefined,
|
|
55
|
-
removeExtension: false,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
async transform(code, id, options) {
|
|
60
|
-
const ssr = options?.ssr ?? false;
|
|
61
|
-
if (!ssr) return null;
|
|
62
|
-
if (!id.match(DEFAULT_CONFIG.FILE_REGEX)) return null;
|
|
63
|
-
if (!code.match('"use client"')) return null;
|
|
64
|
-
|
|
65
|
-
// Get the client manifest
|
|
66
|
-
const clientManifestResult = tryManifest({
|
|
67
|
-
root: userOptions.projectRoot,
|
|
68
|
-
outDir: join(
|
|
69
|
-
userOptions.build.outDir,
|
|
70
|
-
userOptions.build.client
|
|
71
|
-
),
|
|
72
|
-
ssrManifest: false,
|
|
73
|
-
});
|
|
74
|
-
if (clientManifestResult.type === "error") throw clientManifestResult.error;
|
|
75
|
-
clientManifest = clientManifestResult.manifest;
|
|
76
|
-
const [key, value] = normalizer(id);
|
|
77
|
-
const transformed = await transformModuleIfNeeded(
|
|
78
|
-
code,
|
|
79
|
-
id,
|
|
80
|
-
// Pass null for nextLoad since we don't need module loading in the plugin
|
|
81
|
-
null
|
|
82
|
-
);
|
|
83
|
-
if (!transformed) return null;
|
|
84
|
-
if (isDev) {
|
|
85
|
-
return {
|
|
86
|
-
code: transformed,
|
|
87
|
-
map: null,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
const moduleIdIndex = transformed.indexOf(value);
|
|
91
|
-
if (moduleIdIndex === -1) {
|
|
92
|
-
console.warn(
|
|
93
|
-
`[vite-plugin-react-server] Could not find module id in transformed code. Ignoring.`,
|
|
94
|
-
{
|
|
95
|
-
code,
|
|
96
|
-
id,
|
|
97
|
-
transformed,
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
const clientPath = clientManifest[key]?.file;
|
|
103
|
-
|
|
104
|
-
if (!clientPath) {
|
|
105
|
-
console.warn(
|
|
106
|
-
`[vite-plugin-react-server] Could not find client path for ${value}. Ignoring.`
|
|
107
|
-
);
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
code: transformed.replace(key, clientPath),
|
|
112
|
-
map: null,
|
|
113
|
-
};
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
3
|
+
export const { reactTransformPlugin } = await import(`./plugin.${getCondition('')}.js`);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upgrades CSS module code to track class usage.
|
|
3
|
+
*
|
|
4
|
+
* This function modifies the CSS module exports to track which classes are actually used.
|
|
5
|
+
* It adds a proxy around the exports that records class usage in a global Set.
|
|
6
|
+
*
|
|
7
|
+
* @param code The original CSS module code from Vite
|
|
8
|
+
* @returns The upgraded CSS module code with tracking
|
|
9
|
+
*/
|
|
10
|
+
export function upgradeCssModuleCode(code: string): string {
|
|
11
|
+
// Check if this is a CSS module export
|
|
12
|
+
if (code.includes('export default')) {
|
|
13
|
+
// Add tracking code to the CSS module exports
|
|
14
|
+
return code.replace(
|
|
15
|
+
/export default ({[\s\S]*?})/,
|
|
16
|
+
(_match: string, exports: string) => {
|
|
17
|
+
return `
|
|
18
|
+
const originalExports = ${exports};
|
|
19
|
+
const trackedExports = {};
|
|
20
|
+
|
|
21
|
+
// Create a proxy to track class usage
|
|
22
|
+
Object.keys(originalExports).forEach(key => {
|
|
23
|
+
Object.defineProperty(trackedExports, key, {
|
|
24
|
+
get: function() {
|
|
25
|
+
// Track that this class was used
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
window.__cssModuleClassesUsed = window.__cssModuleClassesUsed || new Set();
|
|
28
|
+
window.__cssModuleClassesUsed.add(key);
|
|
29
|
+
}
|
|
30
|
+
return originalExports[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export default trackedExports;
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return code;
|
|
42
|
+
}
|