vite-plugin-react-server 1.1.9 → 1.1.11
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 +208 -27
- package/dist/index.js.map +1 -1
- package/dist/package.json +34 -14
- package/dist/plugin/{css-collector-elements.d.ts → components/css-collector-elements.d.ts} +1 -1
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/components/css-collector-elements.js.map +1 -0
- package/dist/plugin/{css-collector.d.ts → components/css-collector.d.ts} +1 -1
- package/dist/plugin/components/css-collector.d.ts.map +1 -0
- package/dist/plugin/components/css-collector.js.map +1 -0
- package/dist/plugin/components/html.d.ts +4 -0
- package/dist/plugin/components/html.d.ts.map +1 -0
- package/dist/plugin/components/html.js +17 -0
- package/dist/plugin/components/html.js.map +1 -0
- package/dist/plugin/components/index.d.ts +5 -0
- package/dist/plugin/components/index.d.ts.map +1 -0
- package/dist/plugin/components.js +9 -3
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/autoDiscover/index.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/index.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/index.js +8 -0
- package/dist/plugin/config/{resolveAutoDiscover.d.ts → autoDiscover/resolveAutoDiscover.d.ts} +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/{resolveAutoDiscover.js → autoDiscover/resolveAutoDiscover.js} +10 -9
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +10 -10
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +6 -4
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +8 -4
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/index.d.ts +1 -0
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +1 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts +2 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.d.ts +13 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.js +120 -0
- package/dist/plugin/config/resolveEnv.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +34 -11
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
- package/dist/plugin/config/resolveUrlOption.js +1 -2
- package/dist/plugin/config/resolveUrlOption.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -69
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/config.js +17 -0
- package/dist/plugin/config.js.map +1 -0
- package/dist/plugin/env/index.d.ts +2 -0
- package/dist/plugin/env/index.d.ts.map +1 -0
- package/dist/plugin/env/index.js +1 -0
- package/dist/plugin/env/plugin.d.ts +30 -0
- package/dist/plugin/env/plugin.d.ts.map +1 -0
- package/dist/plugin/env/plugin.js +64 -0
- package/dist/plugin/env.js +45 -0
- package/dist/plugin/env.js.map +1 -0
- package/dist/plugin/error/toError.d.ts +6 -0
- package/dist/plugin/error/toError.d.ts.map +1 -0
- package/dist/plugin/error/toError.js +19 -0
- package/dist/plugin/error/toError.js.map +1 -0
- package/dist/plugin/file-preserver/plugin.d.ts +19 -0
- package/dist/plugin/file-preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/file-preserver/plugin.js +108 -0
- package/dist/plugin/file-preserver.js +96 -0
- package/dist/plugin/file-preserver.js.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +10 -2
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createEventHandler.d.ts +1 -1
- package/dist/plugin/helpers/createRscStream.js +1 -1
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/formatMetrics.d.ts +3 -1
- package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/helpers/formatMetrics.js +22 -7
- package/dist/plugin/helpers/formatMetrics.js.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +2 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
- package/dist/plugin/helpers/index.d.ts +24 -0
- package/dist/plugin/helpers/index.d.ts.map +1 -0
- package/dist/plugin/helpers/index.js +31 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +2 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +34 -9
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.js +26 -2
- package/dist/plugin/helpers/metrics.js.map +1 -1
- package/dist/plugin/helpers/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/helpers/moduleRefs.js.map +1 -0
- package/dist/plugin/helpers/requestInfo.d.ts +26 -0
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -0
- package/dist/plugin/helpers/requestInfo.js +66 -0
- package/dist/plugin/helpers/requestInfo.js.map +1 -0
- package/dist/plugin/helpers/requestToRoute.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -0
- package/dist/plugin/{resolvePage.js → helpers/resolvePage.js} +19 -3
- package/dist/plugin/helpers/resolvePage.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js +7 -4
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -0
- package/dist/plugin/{resolveProps.js → helpers/resolveProps.js} +9 -6
- package/dist/plugin/helpers/resolveProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.js +19 -13
- package/dist/plugin/helpers/stashReturnValue.js.map +1 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +0 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/helpers.js +27 -0
- package/dist/plugin/helpers.js.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +1 -1
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +1 -7
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/css-loader.production.js.map +1 -1
- package/dist/plugin/loader/env-loader.development.d.ts +12 -0
- package/dist/plugin/loader/env-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/env-loader.development.js +60 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +1 -8
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/metrics/formatMetrics.d.ts +6 -1
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/metrics/formatMetrics.js +21 -3
- package/dist/plugin/metrics/formatMetrics.js.map +1 -1
- package/dist/plugin/metrics.js +1 -1
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +2 -0
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +1 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +3 -0
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/process-env.d.ts +14 -0
- package/dist/plugin/process-env.d.ts.map +1 -0
- package/dist/plugin/process-env.js +1 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts +11 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.js +47 -0
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -0
- package/dist/plugin/react-client/createWorkerStream.d.ts +9 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +102 -70
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +19 -0
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js +47 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +19 -5
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts +6 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +13 -5
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +2 -13
- package/dist/plugin/react-client/server.d.ts.map +1 -1
- package/dist/plugin/react-client/server.js +123 -121
- package/dist/plugin/react-client/server.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +18 -8
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts.map +1 -1
- package/dist/plugin/react-server/server.js +37 -23
- package/dist/plugin/react-server/server.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +9 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +58 -54
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -1
- package/dist/plugin/react-static/fileWriter.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +21 -23
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPages.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 +3 -2
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.client.js +3 -12
- package/dist/plugin/transformer/plugin.client.js.map +1 -1
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +17 -24
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +1 -10
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.js +40 -38
- package/dist/plugin/types.d.ts +60 -15
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/utils/callServer.d.ts +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.js +3 -17
- package/dist/plugin/utils/callServer.js.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts +2 -0
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -0
- package/dist/plugin/utils/createCallServer.js +28 -0
- package/dist/plugin/utils/createCallServer.js.map +1 -0
- package/dist/plugin/utils/createReactFetcher.d.ts +3 -1
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +11 -11
- package/dist/plugin/utils/createReactFetcher.js.map +1 -1
- package/dist/plugin/utils/env.d.ts +2 -0
- package/dist/plugin/utils/env.d.ts.map +1 -0
- package/dist/plugin/utils/env.js +9 -0
- package/dist/plugin/utils/env.js.map +1 -0
- package/dist/plugin/utils/envUrls.d.ts +9 -0
- package/dist/plugin/utils/envUrls.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.js +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.node.js +11 -0
- package/dist/plugin/utils/envUrls.node.js.map +1 -0
- package/dist/plugin/utils/index.d.ts +2 -1
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +2 -1
- package/dist/plugin/utils/moduleBaseURL.d.ts +3 -0
- package/dist/plugin/utils/moduleBaseURL.d.ts.map +1 -0
- package/dist/plugin/utils/moduleBaseURL.js +4 -0
- package/dist/plugin/utils/urls.d.ts +130 -0
- package/dist/plugin/utils/urls.d.ts.map +1 -0
- package/dist/plugin/utils/urls.js +87 -0
- package/dist/plugin/utils/urls.js.map +1 -0
- package/dist/plugin/utils.js +2 -1
- package/dist/plugin/utils.js.map +1 -1
- package/dist/plugin/vendor/index.d.ts +2 -0
- package/dist/plugin/vendor/index.d.ts.map +1 -0
- package/dist/plugin/vendor/index.js +1 -0
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.client.js.map +1 -0
- package/dist/plugin/vendor/vendor.d.ts +2 -0
- package/dist/plugin/vendor/vendor.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.js +15 -0
- package/dist/plugin/vendor/vendor.js.map +1 -0
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.server.js.map +1 -0
- package/dist/plugin/vendor.js +7 -0
- package/dist/plugin/vendor.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +3 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +37 -23
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +4 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts +2 -7
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +4 -4
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +42 -16
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.js +45 -43
- package/dist/plugin/worker/sendMessage.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +32 -4
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -14
- package/plugin/{css-collector-elements.tsx → components/css-collector-elements.tsx} +1 -1
- package/plugin/{css-collector.tsx → components/css-collector.tsx} +1 -1
- package/plugin/{html.tsx → components/html.tsx} +1 -3
- package/{dist/plugin/components.d.ts → plugin/components/index.ts} +1 -1
- package/plugin/config/autoDiscover/index.ts +10 -0
- package/plugin/config/{resolveAutoDiscover.ts → autoDiscover/resolveAutoDiscover.ts} +16 -12
- package/plugin/config/autoDiscover/resolveBuildPages.ts +10 -11
- package/plugin/config/defaults.tsx +6 -4
- package/plugin/config/index.ts +1 -1
- package/plugin/config/resolveEnv.ts +187 -0
- package/plugin/config/resolveOptions.ts +60 -27
- package/plugin/config/resolveUrlOption.ts +2 -7
- package/plugin/config/resolveUserConfig.ts +145 -98
- package/plugin/env/index.ts +1 -0
- package/plugin/env/plugin.ts +78 -0
- package/plugin/error/toError.ts +19 -0
- package/plugin/file-preserver/plugin.ts +117 -0
- package/plugin/helpers/createCssProps.tsx +14 -6
- package/plugin/helpers/createRscStream.tsx +1 -1
- package/plugin/helpers/formatMetrics.ts +2 -2
- package/plugin/helpers/getRouteFiles.ts +3 -1
- package/plugin/helpers/index.ts +38 -0
- package/plugin/helpers/inputNormalizer.ts +66 -17
- package/plugin/helpers/requestInfo.ts +91 -0
- package/plugin/{resolvePage.ts → helpers/resolvePage.ts} +19 -4
- package/plugin/helpers/resolvePageAndProps.ts +7 -4
- package/plugin/{resolveProps.ts → helpers/resolveProps.ts} +8 -6
- package/plugin/helpers/serializeUserOptions.ts +1 -1
- package/plugin/helpers/tryManifest.ts +0 -1
- package/plugin/loader/createBuildLoader.ts +1 -1
- package/plugin/loader/css-loader.development.ts +2 -8
- package/plugin/loader/env-loader.development.ts +84 -0
- package/plugin/loader/react-loader.ts +1 -10
- package/plugin/metrics/formatMetrics.ts +29 -4
- package/plugin/plugin.client.ts +2 -0
- package/plugin/plugin.server.ts +3 -0
- package/plugin/plugin.ts +1 -3
- package/plugin/preserver/plugin.ts +1 -0
- package/plugin/process-env.ts +13 -0
- package/plugin/react-client/createMessageHandlers.ts +49 -0
- package/plugin/react-client/createWorkerStream.ts +130 -83
- package/plugin/react-client/handleWorkerRscStream.ts +57 -0
- package/plugin/react-client/plugin.ts +30 -17
- package/plugin/react-client/restartWorker.ts +15 -7
- package/plugin/react-client/server.ts +129 -164
- package/plugin/react-server/plugin.ts +26 -13
- package/plugin/react-server/server.ts +40 -35
- package/plugin/react-static/collectHtmlWorkerContent.ts +13 -1
- package/plugin/react-static/configurePreviewServer.ts +75 -62
- package/plugin/react-static/fileWriter.ts +1 -1
- package/plugin/react-static/plugin.ts +23 -30
- package/plugin/root.ts +7 -1
- package/plugin/transformer/plugin.client.ts +4 -12
- package/plugin/transformer/plugin.server.ts +18 -25
- package/plugin/transformer/upgradeCssModuleCode.ts +39 -39
- package/plugin/types/env.d.ts +7 -0
- package/plugin/types.ts +80 -29
- package/plugin/utils/callServer.ts +3 -24
- package/plugin/utils/createCallServer.ts +26 -0
- package/plugin/utils/createReactFetcher.ts +14 -12
- package/plugin/utils/env.ts +1 -0
- package/plugin/utils/envUrls.node.ts +19 -0
- package/plugin/utils/envUrls.ts +8 -0
- package/plugin/utils/index.ts +2 -1
- package/plugin/utils/moduleBaseURL.ts +7 -0
- package/plugin/utils/urls.ts +217 -0
- package/plugin/vendor/index.ts +1 -0
- package/plugin/vendor/vendor.ts +6 -0
- package/plugin/worker/createWorker.ts +41 -30
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +4 -1
- package/plugin/worker/html/html-worker.development.tsx +2 -1
- package/plugin/worker/html/html-worker.production.tsx +2 -1
- package/plugin/worker/rsc/handleRender.ts +6 -12
- package/plugin/worker/rsc/messageHandler.tsx +53 -20
- package/plugin/worker/rsc/rsc-worker.development.ts +23 -9
- package/plugin/worker/rsc/rsc-worker.production.ts +23 -7
- package/plugin/worker/types.ts +35 -4
- package/dist/plugin/components.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.js.map +0 -1
- package/dist/plugin/copy.d.ts +0 -7
- package/dist/plugin/copy.d.ts.map +0 -1
- package/dist/plugin/copy.js +0 -30
- package/dist/plugin/css-collector-elements.d.ts.map +0 -1
- package/dist/plugin/css-collector-elements.js.map +0 -1
- package/dist/plugin/css-collector.d.ts.map +0 -1
- package/dist/plugin/css-collector.js.map +0 -1
- package/dist/plugin/getCondition.d.ts +0 -2
- package/dist/plugin/getCondition.d.ts.map +0 -1
- package/dist/plugin/html.d.ts +0 -4
- package/dist/plugin/html.d.ts.map +0 -1
- package/dist/plugin/html.js +0 -18
- package/dist/plugin/html.js.map +0 -1
- package/dist/plugin/manifest.d.ts +0 -6
- package/dist/plugin/manifest.d.ts.map +0 -1
- package/dist/plugin/manifest.js +0 -13
- package/dist/plugin/moduleRefs.d.ts.map +0 -1
- package/dist/plugin/moduleRefs.js.map +0 -1
- package/dist/plugin/resolvePage.d.ts.map +0 -1
- package/dist/plugin/resolvePage.js.map +0 -1
- package/dist/plugin/resolveProps.d.ts.map +0 -1
- package/dist/plugin/resolveProps.js.map +0 -1
- package/dist/plugin/utils/pageURL.d.ts +0 -2
- package/dist/plugin/utils/pageURL.d.ts.map +0 -1
- package/dist/plugin/utils/pageURL.js +0 -21
- package/dist/plugin/utils/pageURL.js.map +0 -1
- package/dist/plugin/vendor.client.d.ts.map +0 -1
- package/dist/plugin/vendor.client.js.map +0 -1
- package/dist/plugin/vendor.server.d.ts.map +0 -1
- package/dist/plugin/vendor.server.js.map +0 -1
- package/plugin/copy.ts +0 -39
- package/plugin/manifest.ts +0 -24
- package/plugin/utils/pageURL.ts +0 -28
- /package/dist/plugin/{css-collector-elements.js → components/css-collector-elements.js} +0 -0
- /package/dist/plugin/{css-collector.js → components/css-collector.js} +0 -0
- /package/{plugin/components.ts → dist/plugin/components/index.js} +0 -0
- /package/dist/plugin/{getCondition.js → config/resolveDevServerConfig.js} +0 -0
- /package/dist/plugin/{moduleRefs.d.ts → helpers/moduleRefs.d.ts} +0 -0
- /package/dist/plugin/{moduleRefs.js → helpers/moduleRefs.js} +0 -0
- /package/dist/plugin/{resolvePage.d.ts → helpers/resolvePage.d.ts} +0 -0
- /package/dist/plugin/{resolveProps.d.ts → helpers/resolveProps.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.d.ts → vendor/vendor.client.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.js → vendor/vendor.client.js} +0 -0
- /package/dist/plugin/{vendor.server.d.ts → vendor/vendor.server.d.ts} +0 -0
- /package/dist/plugin/{vendor.server.js → vendor/vendor.server.js} +0 -0
- /package/plugin/{getCondition.ts → config/resolveDevServerConfig.tsx} +0 -0
- /package/plugin/{moduleRefs.ts → helpers/moduleRefs.ts} +0 -0
- /package/plugin/{vendor.client.ts → vendor/vendor.client.ts} +0 -0
- /package/plugin/{vendor.server.ts → vendor/vendor.server.ts} +0 -0
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { PreviewServer } from "vite";
|
|
2
|
-
import { MIME_TYPES } from "../config/mimeTypes.js";
|
|
3
2
|
import type { ResolvedUserOptions } from "../types.js";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import { createReadStream } from "node:fs";
|
|
6
5
|
import { stat } from "node:fs/promises";
|
|
7
6
|
import { pipeline } from "node:stream/promises";
|
|
7
|
+
import { requestInfo } from "../helpers/requestInfo.js";
|
|
8
|
+
|
|
9
|
+
interface StreamError extends Error {
|
|
10
|
+
code?: string;
|
|
11
|
+
}
|
|
8
12
|
|
|
9
13
|
export async function configurePreviewServer({
|
|
10
14
|
server,
|
|
@@ -13,77 +17,86 @@ export async function configurePreviewServer({
|
|
|
13
17
|
server: PreviewServer;
|
|
14
18
|
userOptions: ResolvedUserOptions;
|
|
15
19
|
}) {
|
|
16
|
-
const staticHostDir = join(
|
|
20
|
+
const staticHostDir = join(
|
|
21
|
+
userOptions.projectRoot,
|
|
22
|
+
userOptions.build.outDir,
|
|
23
|
+
userOptions.build.static
|
|
24
|
+
);
|
|
17
25
|
server.middlewares.use(async (req, res, next) => {
|
|
18
|
-
if(!req.url) {
|
|
19
|
-
console.log("no url")
|
|
26
|
+
if (!req.url) {
|
|
20
27
|
return next();
|
|
21
28
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const ext = value.slice(value.lastIndexOf("."));
|
|
25
|
-
// handle index.html
|
|
26
|
-
const isHtml = userOptions.autoDiscover.htmlPattern(value)
|
|
27
|
-
if (isHtml || (req.headers.accept?.includes("text/html"))) {
|
|
28
|
-
const indexHtml = isHtml ? join(staticHostDir, value) : join(staticHostDir, value, userOptions.build.htmlOutputPath);
|
|
29
|
-
try {
|
|
30
|
-
const stats = await stat(indexHtml);
|
|
31
|
-
if (stats.isFile()) {
|
|
32
|
-
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
33
|
-
await pipeline(createReadStream(indexHtml), res);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
} catch {
|
|
37
|
-
// File doesn't exist, continue to next middleware
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const isRsc = userOptions.autoDiscover.rscPattern(value)
|
|
41
|
-
if (isRsc || (req.headers.accept?.includes("text/x-component"))) {
|
|
42
|
-
const rsc = isRsc ? join(staticHostDir, value) : join(staticHostDir, value, userOptions.build.rscOutputPath);
|
|
43
|
-
try {
|
|
44
|
-
const stats = await stat(rsc);
|
|
45
|
-
if (stats.isFile()) {
|
|
46
|
-
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
47
|
-
await pipeline(createReadStream(rsc), res);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
} catch {
|
|
51
|
-
// File doesn't exist, continue to next middleware
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const isCss = userOptions.autoDiscover.cssPattern(value)
|
|
55
|
-
if (isCss || (req.headers.accept?.includes("text/css") && (ext === ""))) {
|
|
56
|
-
const css = isCss ? join(staticHostDir, value) : join(staticHostDir, value);
|
|
57
|
-
try {
|
|
58
|
-
const stats = await stat(css);
|
|
59
|
-
if (stats.isFile()) {
|
|
60
|
-
res.setHeader("Content-Type", "text/css; charset=utf-8");
|
|
61
|
-
await pipeline(createReadStream(css), res);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
} catch {
|
|
65
|
-
// File doesn't exist, continue to next middleware
|
|
66
|
-
}
|
|
67
|
-
}
|
|
29
|
+
const { contentType, filePath } = requestInfo(req, userOptions, staticHostDir);
|
|
30
|
+
|
|
68
31
|
// Handle static files including CSS
|
|
69
|
-
if (
|
|
70
|
-
const filePath = join(staticHostDir, value);
|
|
32
|
+
if (filePath) {
|
|
71
33
|
try {
|
|
72
34
|
const stats = await stat(filePath);
|
|
73
35
|
if (stats.isFile()) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
36
|
+
res.setHeader("Content-Type", contentType);
|
|
37
|
+
|
|
38
|
+
// Create abort controller for the stream
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const { signal } = controller;
|
|
41
|
+
|
|
42
|
+
// Check if response is still writable before streaming
|
|
43
|
+
if (!res.writable) {
|
|
44
|
+
res.statusCode = 499;
|
|
45
|
+
res.end("Client closed request");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const readStream = createReadStream(filePath);
|
|
51
|
+
readStream.on('error', () => {
|
|
52
|
+
if (!res.writable) {
|
|
53
|
+
controller.abort();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
await pipeline(readStream, res, { signal });
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const streamError = error as StreamError;
|
|
59
|
+
// Handle different error cases
|
|
60
|
+
if (streamError.code === 'ERR_STREAM_PREMATURE_CLOSE' ||
|
|
61
|
+
streamError.name === 'AbortError') {
|
|
62
|
+
// Client closed the connection
|
|
63
|
+
if (res.writable) {
|
|
64
|
+
res.statusCode = 499;
|
|
65
|
+
res.end("Client closed request");
|
|
66
|
+
}
|
|
67
|
+
} else if (streamError.code === 'ENOENT') {
|
|
68
|
+
// File not found
|
|
69
|
+
res.statusCode = 404;
|
|
70
|
+
server.config.logger.error(`File not found: ${filePath}. ${streamError.message}`, {
|
|
71
|
+
error: streamError,
|
|
72
|
+
});
|
|
73
|
+
res.end("File not found");
|
|
74
|
+
} else {
|
|
75
|
+
// Server error
|
|
76
|
+
server.config.logger.error(`Error loading file: ${filePath}. ${streamError.message}`, {
|
|
77
|
+
error: streamError,
|
|
78
|
+
});
|
|
79
|
+
res.statusCode = 500;
|
|
80
|
+
res.end("Internal server error");
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
81
83
|
}
|
|
82
|
-
await pipeline(createReadStream(filePath), res);
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
|
-
} catch {
|
|
86
|
-
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const err = error as Error;
|
|
88
|
+
// Handle file system errors
|
|
89
|
+
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
90
|
+
res.statusCode = 404;
|
|
91
|
+
res.end("File not found");
|
|
92
|
+
} else {
|
|
93
|
+
server.config.logger.error(`Error loading file: ${filePath}.`, {
|
|
94
|
+
error: err,
|
|
95
|
+
});
|
|
96
|
+
res.statusCode = 500;
|
|
97
|
+
res.end("Internal server error");
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
next();
|
|
@@ -13,7 +13,7 @@ import type { FileWriterOptions } from "../types.js";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import { createWriteStream } from "node:fs";
|
|
15
15
|
import { mkdir } from "node:fs/promises";
|
|
16
|
-
import { Readable, Transform } from "node:stream";
|
|
16
|
+
import { type Readable, Transform } from "node:stream";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Writes HTML and RSC files for a route using streams
|
|
@@ -39,7 +39,7 @@ import { type StreamPluginOptions } from "../types.js";
|
|
|
39
39
|
import { renderPages } from "./renderPages.js";
|
|
40
40
|
import { getBundleManifest } from "../helpers/getBundleManifest.js";
|
|
41
41
|
import { createWorker } from "../worker/createWorker.js";
|
|
42
|
-
import { resolveAutoDiscover } from "../config/resolveAutoDiscover.js";
|
|
42
|
+
import { resolveAutoDiscover } from "../config/autoDiscover/resolveAutoDiscover.js";
|
|
43
43
|
import { getCondition } from "../config/getCondition.js";
|
|
44
44
|
import {
|
|
45
45
|
serializedOptions,
|
|
@@ -49,6 +49,8 @@ import { collectManifestCss } from "../helpers/collectManifestCss.js";
|
|
|
49
49
|
import { createCssProps } from "../helpers/createCssProps.js";
|
|
50
50
|
import { tryManifest } from "../helpers/tryManifest.js";
|
|
51
51
|
import { performance } from "node:perf_hooks";
|
|
52
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
53
|
+
import { baseURL } from "../utils/envUrls.node.js";
|
|
52
54
|
|
|
53
55
|
if (getCondition() !== "react-server") {
|
|
54
56
|
throw new Error(
|
|
@@ -64,7 +66,6 @@ let userOptions: ResolvedUserOptions;
|
|
|
64
66
|
let autoDiscoveredFiles: AutoDiscoveredFiles | null = null;
|
|
65
67
|
let serverManifest: Manifest | undefined = undefined;
|
|
66
68
|
let buildLoader: Awaited<ReturnType<typeof createBuildLoader>> | undefined;
|
|
67
|
-
|
|
68
69
|
export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
69
70
|
meta: ReactStreamPluginMeta;
|
|
70
71
|
}> {
|
|
@@ -92,7 +93,6 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
92
93
|
if (config.root && config.root !== userOptions.projectRoot) {
|
|
93
94
|
userOptions.projectRoot = config.root;
|
|
94
95
|
}
|
|
95
|
-
|
|
96
96
|
const autoDiscoverResult = await resolveAutoDiscover({
|
|
97
97
|
config,
|
|
98
98
|
configEnv,
|
|
@@ -103,7 +103,6 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
103
103
|
throw autoDiscoverResult.error;
|
|
104
104
|
}
|
|
105
105
|
autoDiscoveredFiles = autoDiscoverResult.autoDiscoveredFiles;
|
|
106
|
-
|
|
107
106
|
const resolvedConfig = resolveUserConfig({
|
|
108
107
|
condition: "react-server",
|
|
109
108
|
config,
|
|
@@ -121,7 +120,6 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
121
120
|
configResolved(config) {
|
|
122
121
|
resolvedConfig = config;
|
|
123
122
|
},
|
|
124
|
-
|
|
125
123
|
async buildStart() {
|
|
126
124
|
timing.buildStart = Date.now();
|
|
127
125
|
if (userOptions.onEvent && autoDiscoveredFiles) {
|
|
@@ -136,10 +134,21 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
136
134
|
},
|
|
137
135
|
|
|
138
136
|
async renderStart() {
|
|
137
|
+
|
|
139
138
|
timing.renderStart = Date.now();
|
|
140
139
|
},
|
|
141
140
|
|
|
142
141
|
async writeBundle(options, bundle) {
|
|
142
|
+
if (userOptions.onEvent) {
|
|
143
|
+
userOptions.onEvent({
|
|
144
|
+
type: "build.writeBundle.static-server",
|
|
145
|
+
data: {
|
|
146
|
+
pages: Array.from(autoDiscoveredFiles?.urlMap.keys() ?? []),
|
|
147
|
+
options,
|
|
148
|
+
bundle,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
143
152
|
try {
|
|
144
153
|
const bundleManifest = getBundleManifest<false>({
|
|
145
154
|
bundle,
|
|
@@ -166,7 +175,7 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
166
175
|
throw clientManifestResult.error;
|
|
167
176
|
}
|
|
168
177
|
const clientManifest = clientManifestResult.manifest;
|
|
169
|
-
|
|
178
|
+
|
|
170
179
|
buildLoader = await createBuildLoader(
|
|
171
180
|
{
|
|
172
181
|
userConfig,
|
|
@@ -266,34 +275,12 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
266
275
|
cssFilesByPage.set(url, pageCssMap);
|
|
267
276
|
}
|
|
268
277
|
|
|
269
|
-
if (userOptions.onEvent) {
|
|
270
|
-
userOptions.onEvent({
|
|
271
|
-
type: "build.writeBundle",
|
|
272
|
-
data: {
|
|
273
|
-
pages: Array.from(autoDiscoveredFiles?.urlMap.keys() ?? []),
|
|
274
|
-
options,
|
|
275
|
-
bundle,
|
|
276
|
-
manifest: serverManifest,
|
|
277
|
-
},
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
278
|
const staticManifest = autoDiscoveredFiles?.staticManifest ?? {};
|
|
281
279
|
const indexHtml = staticManifest?.["index.html"]?.file;
|
|
282
|
-
const safeParseURL = (() => {
|
|
283
|
-
try {
|
|
284
|
-
return new URL(join(userOptions.moduleBasePath, indexHtml), userOptions.moduleBaseURL).href;
|
|
285
|
-
} catch (error) {
|
|
286
|
-
return userOptions.moduleBaseURL + join(userOptions.moduleBasePath, indexHtml);
|
|
287
|
-
}
|
|
288
|
-
})();
|
|
289
280
|
const pipeableStreamOptions = {
|
|
290
281
|
...userOptions.pipeableStreamOptions,
|
|
291
282
|
bootstrapModules: [
|
|
292
|
-
...(
|
|
293
|
-
? [
|
|
294
|
-
safeParseURL,
|
|
295
|
-
]
|
|
296
|
-
: []),
|
|
283
|
+
...(indexHtml ? [baseURL(indexHtml)] : []),
|
|
297
284
|
...(userOptions.pipeableStreamOptions?.bootstrapModules ?? []),
|
|
298
285
|
],
|
|
299
286
|
};
|
|
@@ -309,7 +296,7 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
309
296
|
? resolvedConfig.envPrefix
|
|
310
297
|
: Array.isArray(resolvedConfig.envPrefix)
|
|
311
298
|
? resolvedConfig.envPrefix[0]
|
|
312
|
-
:
|
|
299
|
+
: DEFAULT_CONFIG.ENV_PREFIX;
|
|
313
300
|
const routeCount = autoDiscoveredFiles?.urlMap.size ?? 0;
|
|
314
301
|
const maxListeners = routeCount + 1;
|
|
315
302
|
const workerResult = await createWorker({
|
|
@@ -319,6 +306,7 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
319
306
|
reverseCondition: "react-client",
|
|
320
307
|
maxListeners: maxListeners,
|
|
321
308
|
envPrefix: viteEnvPrefix,
|
|
309
|
+
logger: this.environment.logger,
|
|
322
310
|
workerData: {
|
|
323
311
|
resolvedConfig: serializeResolvedConfig(resolvedConfig),
|
|
324
312
|
userOptions: {
|
|
@@ -390,6 +378,11 @@ export function reactStaticPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
390
378
|
this.environment.logger.info(
|
|
391
379
|
`Rendered ${finalResult.completedRoutes.size} unique routes in ${finalResult.streamMetrics.duration}ms`
|
|
392
380
|
);
|
|
381
|
+
if(process.env['NODE_ENV'] !== 'production') {
|
|
382
|
+
this.environment.logger.warn(
|
|
383
|
+
`THIS IS BUILD IS NOT INTENDED FOR PRODUCTION (${process.env['NODE_ENV']})`
|
|
384
|
+
);
|
|
385
|
+
}
|
|
393
386
|
|
|
394
387
|
// Update timing
|
|
395
388
|
timing.render = Date.now() - (timing.renderStart ?? timing.start);
|
package/plugin/root.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
export const pluginRoot = dirname(fileURLToPath(import.meta.url));
|
|
4
|
-
export const
|
|
4
|
+
export const userProjectRoot =
|
|
5
|
+
process.argv
|
|
6
|
+
.find((arg) => arg.includes("node_modules"))
|
|
7
|
+
?.match(/^(.+?)\/node_modules\/.+$/)?.[1] ||
|
|
8
|
+
process.env["npm_config_local_prefix"] ||
|
|
9
|
+
process.cwd();
|
|
10
|
+
export const isLinked = !pluginRoot.startsWith(userProjectRoot);
|
|
@@ -37,15 +37,7 @@ export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
|
37
37
|
if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
|
|
38
38
|
userOptions = resolvedOptionsResult.userOptions;
|
|
39
39
|
let staticManifest: Manifest;
|
|
40
|
-
|
|
41
|
-
if(userOptions.moduleBasePath !== '' && !id.startsWith(userOptions.moduleBasePath)) {
|
|
42
|
-
id = join(userOptions.moduleBasePath, id);
|
|
43
|
-
}
|
|
44
|
-
if(!id.startsWith('/')) {
|
|
45
|
-
id = '/' + id;
|
|
46
|
-
}
|
|
47
|
-
return id;
|
|
48
|
-
}
|
|
40
|
+
|
|
49
41
|
return {
|
|
50
42
|
name: "vite:react-server-action-transform",
|
|
51
43
|
enforce: "pre",
|
|
@@ -80,11 +72,11 @@ export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
|
80
72
|
if (isClient) {
|
|
81
73
|
return null;
|
|
82
74
|
}
|
|
75
|
+
const [key, value] = userOptions.normalizer(id);
|
|
83
76
|
if (isServer && isBuild) {
|
|
84
|
-
const [key] = userOptions.normalizer(id);
|
|
85
77
|
id = key + ".js";
|
|
86
78
|
}
|
|
87
|
-
const finalID =
|
|
79
|
+
const finalID = userOptions.moduleID(value);
|
|
88
80
|
const transformed = await transformModuleIfNeeded(code, finalID, null);
|
|
89
81
|
if (!transformed) return null;
|
|
90
82
|
return {
|
|
@@ -98,7 +90,7 @@ export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
|
98
90
|
if (!chunk.fileName.includes(".client")) return null;
|
|
99
91
|
|
|
100
92
|
// Get the original file name without extension
|
|
101
|
-
const originalName = chunk.fileName.replace(
|
|
93
|
+
const originalName = chunk.fileName.replace(userOptions.autoDiscover.moduleExtension, "");
|
|
102
94
|
|
|
103
95
|
// Find matching entry in static manifest
|
|
104
96
|
const manifestEntry = Object.entries(staticManifest).find(([_, info]) =>
|
|
@@ -38,42 +38,34 @@ export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
|
38
38
|
|
|
39
39
|
let staticManifest: Manifest;
|
|
40
40
|
|
|
41
|
-
const getID = (id: string) => {
|
|
42
|
-
if(userOptions.moduleBasePath !== '' && !id.startsWith(userOptions.moduleBasePath)) {
|
|
43
|
-
id = join(userOptions.moduleBasePath, id);
|
|
44
|
-
}
|
|
45
|
-
if(!id.startsWith('/')) {
|
|
46
|
-
id = '/' + id;
|
|
47
|
-
}
|
|
48
|
-
return id;
|
|
49
|
-
}
|
|
50
41
|
return {
|
|
51
42
|
name: "vite:react-server-transform",
|
|
52
43
|
enforce: "pre", // Run before Vite's transforms
|
|
53
|
-
async config(
|
|
44
|
+
async config(_config, configEnv) {
|
|
54
45
|
isBuild = configEnv.command !== "serve";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
if (isBuild) {
|
|
47
|
+
const staticManifestResult = await tryManifest({
|
|
48
|
+
root: userOptions.projectRoot,
|
|
49
|
+
ssrManifest: false,
|
|
50
|
+
outDir: join(userOptions.build.outDir, userOptions.build.static),
|
|
51
|
+
});
|
|
52
|
+
if (staticManifestResult.type === "error") {
|
|
53
|
+
throw staticManifestResult.error;
|
|
54
|
+
}
|
|
55
|
+
staticManifest = staticManifestResult.manifest;
|
|
63
56
|
}
|
|
64
|
-
staticManifest = staticManifestResult.manifest;
|
|
65
57
|
},
|
|
66
58
|
async transform(code, id, options) {
|
|
67
59
|
const ssr = options?.ssr;
|
|
68
60
|
if (!ssr) return null;
|
|
69
61
|
if (!userOptions.autoDiscover.modulePattern(id)) return null;
|
|
70
62
|
if (!code.match('"use client"')) return null;
|
|
71
|
-
|
|
63
|
+
|
|
64
|
+
const [key, value] = userOptions.normalizer(id);
|
|
72
65
|
if (isBuild) {
|
|
73
|
-
const [key, value] = userOptions.normalizer(id);
|
|
74
66
|
if (staticManifest) {
|
|
75
67
|
if (value in staticManifest) {
|
|
76
|
-
id = staticManifest[value].file
|
|
68
|
+
id = userOptions.moduleID(staticManifest[value].file);
|
|
77
69
|
} else {
|
|
78
70
|
const hash = this.emitFile({
|
|
79
71
|
id,
|
|
@@ -84,16 +76,17 @@ export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
|
84
76
|
// get fileName from hash
|
|
85
77
|
|
|
86
78
|
const fileName = this.getFileName(hash);
|
|
87
|
-
id = fileName;
|
|
79
|
+
id = userOptions.moduleID(fileName);
|
|
88
80
|
}
|
|
89
81
|
} else {
|
|
90
82
|
throw new Error(`Client manifest not found.`);
|
|
91
83
|
}
|
|
84
|
+
} else {
|
|
85
|
+
id = join(userOptions.moduleBasePath, value);
|
|
92
86
|
}
|
|
93
|
-
const finalID = getID(id);
|
|
94
87
|
const transformed = await transformModuleIfNeeded(
|
|
95
88
|
code,
|
|
96
|
-
|
|
89
|
+
id,
|
|
97
90
|
// Pass null for nextLoad since we don't need module loading in the plugin
|
|
98
91
|
null
|
|
99
92
|
);
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function upgradeCssModuleCode(code: string): string {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
// export default trackedExports;
|
|
36
|
+
// `;
|
|
37
|
+
// }
|
|
38
|
+
// );
|
|
39
|
+
// }
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
}
|
|
41
|
+
// return code;
|
|
42
|
+
// }
|