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
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from "../types.js";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import type { OutputOptions, PreRenderedAsset, PreRenderedChunk } from "rollup";
|
|
9
|
+
import { DEFAULT_CONFIG } from "./defaults.js";
|
|
9
10
|
|
|
10
11
|
let stashedUserConfig: Record<string, ResolvedUserConfig | null> = {};
|
|
11
12
|
|
|
@@ -31,7 +32,12 @@ export function resolveUserConfig({
|
|
|
31
32
|
const ssr =
|
|
32
33
|
typeof config.build?.ssr === "boolean"
|
|
33
34
|
? config.build?.ssr
|
|
34
|
-
: Boolean(configEnv.isSsrBuild) ||
|
|
35
|
+
: Boolean(configEnv.isSsrBuild) ||
|
|
36
|
+
condition === "react-server" ||
|
|
37
|
+
(typeof process.env["VITE_SSR"] === "string"
|
|
38
|
+
? process.env["VITE_SSR"] === "true" ||
|
|
39
|
+
process.env["VITE_SSR"] === "1"
|
|
40
|
+
: Boolean(process.env["VITE_SSR"]));
|
|
35
41
|
const envDir =
|
|
36
42
|
condition === "react-client" && ssr
|
|
37
43
|
? userOptions.build.client
|
|
@@ -59,40 +65,86 @@ export function resolveUserConfig({
|
|
|
59
65
|
if (!ssr || !input) {
|
|
60
66
|
return fallback(info, false);
|
|
61
67
|
}
|
|
62
|
-
const [, value] = userOptions.normalizer(
|
|
63
|
-
input
|
|
64
|
-
);
|
|
68
|
+
const [, value] = userOptions.normalizer(input);
|
|
65
69
|
const entry = autoDiscoveredFiles.staticManifest[value];
|
|
66
|
-
if
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
if (
|
|
71
|
+
entry?.name &&
|
|
72
|
+
info.type === "asset" &&
|
|
73
|
+
userOptions.autoDiscover.cssPattern(value)
|
|
74
|
+
) {
|
|
75
|
+
const withoutExt = entry.name?.split(".")[0];
|
|
76
|
+
const found = entry.css?.find((css) =>
|
|
77
|
+
css.startsWith(withoutExt as string)
|
|
78
|
+
);
|
|
79
|
+
if (found) {
|
|
80
|
+
return found;
|
|
71
81
|
} else {
|
|
72
|
-
return entry.file
|
|
82
|
+
return entry.file;
|
|
73
83
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return entry.file
|
|
84
|
+
} else if (entry) {
|
|
85
|
+
return entry.file;
|
|
77
86
|
}
|
|
78
87
|
return fallback(info, true);
|
|
79
88
|
};
|
|
89
|
+
const userDefinedOutput = config.build?.rollupOptions?.output;
|
|
90
|
+
const hasOtherOutput =
|
|
91
|
+
Array.isArray(userDefinedOutput) && userDefinedOutput.length > 1;
|
|
92
|
+
const hasValidOutput = userDefinedOutput && !hasOtherOutput;
|
|
93
|
+
const hasObjectOutput =
|
|
94
|
+
userDefinedOutput &&
|
|
95
|
+
!hasOtherOutput &&
|
|
96
|
+
typeof userDefinedOutput === "object" &&
|
|
97
|
+
userDefinedOutput !== null;
|
|
98
|
+
|
|
99
|
+
const userDefinedAssetFileNames = hasObjectOutput
|
|
100
|
+
? "assetFileNames" in userDefinedOutput
|
|
101
|
+
? userDefinedOutput.assetFileNames
|
|
102
|
+
: undefined
|
|
103
|
+
: // find the other asset file names
|
|
104
|
+
hasOtherOutput
|
|
105
|
+
? (userDefinedOutput.find((o) => o.assetFileNames) as OutputOptions)
|
|
106
|
+
.assetFileNames
|
|
107
|
+
: undefined;
|
|
108
|
+
|
|
109
|
+
const userDefinedChunkFileNames = hasValidOutput
|
|
110
|
+
? "chunkFileNames" in userDefinedOutput
|
|
111
|
+
? userDefinedOutput.chunkFileNames
|
|
112
|
+
: undefined
|
|
113
|
+
: undefined;
|
|
114
|
+
const userDefinedEntryFileNames = hasValidOutput
|
|
115
|
+
? "entryFileNames" in userDefinedOutput
|
|
116
|
+
? userDefinedOutput.entryFileNames
|
|
117
|
+
: undefined
|
|
118
|
+
: undefined;
|
|
119
|
+
|
|
120
|
+
let stashedReturns: Record<string, string> = {};
|
|
80
121
|
const pluginOutput = {
|
|
81
122
|
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
82
123
|
? userOptions.moduleBase
|
|
83
124
|
: undefined,
|
|
84
|
-
entryFileNames:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
125
|
+
entryFileNames:
|
|
126
|
+
userDefinedEntryFileNames ??
|
|
127
|
+
((info) => {
|
|
128
|
+
const input = info.facadeModuleId;
|
|
129
|
+
return handleSsrName(info, input, userOptions.build.entryFile, ssr);
|
|
130
|
+
}),
|
|
131
|
+
assetFileNames: process.env["VITEST"]
|
|
132
|
+
? undefined
|
|
133
|
+
: userDefinedAssetFileNames ??
|
|
134
|
+
((i) => {
|
|
135
|
+
const input = i.originalFileNames[0];
|
|
136
|
+
if (!stashedReturns[input]) {
|
|
137
|
+
const r = handleSsrName(i, input, userOptions.build.assetFile, ssr);
|
|
138
|
+
stashedReturns[input] = r;
|
|
139
|
+
}
|
|
140
|
+
return stashedReturns[input];
|
|
141
|
+
}),
|
|
142
|
+
chunkFileNames:
|
|
143
|
+
userDefinedChunkFileNames ??
|
|
144
|
+
((i) => {
|
|
145
|
+
const input = i.facadeModuleId;
|
|
146
|
+
return handleSsrName(i, input, userOptions.build.chunkFile, ssr);
|
|
147
|
+
}),
|
|
96
148
|
format: "esm",
|
|
97
149
|
exports: "named",
|
|
98
150
|
} satisfies OutputOptions;
|
|
@@ -103,32 +155,71 @@ export function resolveUserConfig({
|
|
|
103
155
|
config.build?.rollupOptions?.output !== null
|
|
104
156
|
? [config.build?.rollupOptions?.output, pluginOutput]
|
|
105
157
|
: pluginOutput;
|
|
106
|
-
const vitePrefix = config.envPrefix ??
|
|
107
|
-
const mode =
|
|
108
|
-
process.env["NODE_ENV"] === "development"
|
|
109
|
-
? "development"
|
|
110
|
-
: config.mode
|
|
111
|
-
? config.mode
|
|
112
|
-
: configEnv.mode
|
|
113
|
-
? configEnv.mode
|
|
114
|
-
: configEnv.command === "build"
|
|
115
|
-
? "production"
|
|
116
|
-
: "development";
|
|
158
|
+
const vitePrefix = config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX;
|
|
159
|
+
const mode = config.mode ?? process.env["VITE_MODE"];
|
|
117
160
|
const minify = config.build?.minify;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
161
|
+
|
|
162
|
+
const srrConfig = {
|
|
163
|
+
...config.ssr,
|
|
164
|
+
target: config.ssr?.target ?? "node",
|
|
165
|
+
optimizeDeps: {
|
|
166
|
+
...config.ssr?.optimizeDeps,
|
|
167
|
+
include: config.ssr?.optimizeDeps?.include ?? [
|
|
168
|
+
"react",
|
|
169
|
+
"react-dom",
|
|
170
|
+
"react-server-dom-esm/client",
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
resolve: {
|
|
174
|
+
...config.ssr?.resolve,
|
|
175
|
+
externalConditions: config.ssr?.resolve?.externalConditions ?? [
|
|
176
|
+
"react-server",
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
let publicOrigin =
|
|
181
|
+
userOptions.publicOrigin ?? process.env.VITE_PUBLIC_ORIGIN ?? "";
|
|
182
|
+
let PROD = mode === "production";
|
|
183
|
+
let DEV = mode === "development";
|
|
184
|
+
if (configEnv.command === "serve" && !configEnv.isPreview) {
|
|
185
|
+
publicOrigin = `http${config.server?.https ? "s" : ""}://${
|
|
186
|
+
typeof config.server?.host === "string"
|
|
187
|
+
? config.server?.host
|
|
188
|
+
: "localhost"
|
|
189
|
+
}:${typeof config.server?.port === "number" ? config.server?.port : 5173}`;
|
|
190
|
+
}
|
|
191
|
+
const ssrDefine = ssr
|
|
192
|
+
? {
|
|
193
|
+
[`process.env.${vitePrefix}SSR`]: `${ssr}`,
|
|
194
|
+
[`process.env.${vitePrefix}DEV`]: `${DEV}`,
|
|
195
|
+
[`process.env.${vitePrefix}PROD`]: `${PROD}`,
|
|
196
|
+
[`process.env.${vitePrefix}MODE`]: `"${mode}"`,
|
|
197
|
+
[`process.env.${vitePrefix}BASE_URL`]: `"${userOptions.moduleBaseURL}"`,
|
|
198
|
+
[`process.env.${vitePrefix}PUBLIC_ORIGIN`]: `"${publicOrigin}"`,
|
|
199
|
+
}
|
|
200
|
+
: {};
|
|
201
|
+
const define = {
|
|
202
|
+
...config.define,
|
|
203
|
+
[`import.meta.env.PUBLIC_ORIGIN`]: `"${publicOrigin}"`,
|
|
204
|
+
...ssrDefine,
|
|
205
|
+
};
|
|
206
|
+
// these will never be cleaned up, because, we are resolving the user config
|
|
207
|
+
// and it's assumed the thread closes after this and we don't want
|
|
208
|
+
// it to change after the config has been resolved
|
|
209
|
+
if (process.env.VITE_BASE_URL !== userOptions.moduleBaseURL) {
|
|
210
|
+
process.env.VITE_BASE_URL = userOptions.moduleBaseURL;
|
|
211
|
+
}
|
|
212
|
+
if (process.env.VITE_PUBLIC_ORIGIN !== publicOrigin) {
|
|
213
|
+
process.env.VITE_PUBLIC_ORIGIN = publicOrigin;
|
|
214
|
+
}
|
|
215
|
+
|
|
125
216
|
if (condition === "react-client") {
|
|
126
217
|
// client plugin build options (client plugin still outputs server files)
|
|
127
218
|
const clientConfig = {
|
|
128
219
|
...config,
|
|
129
220
|
root: root,
|
|
130
221
|
mode: mode,
|
|
131
|
-
base:
|
|
222
|
+
base: userOptions.moduleBaseURL,
|
|
132
223
|
envPrefix: vitePrefix,
|
|
133
224
|
resolve: {
|
|
134
225
|
...config.resolve,
|
|
@@ -138,31 +229,18 @@ export function resolveUserConfig({
|
|
|
138
229
|
"react-server-dom-esm/client",
|
|
139
230
|
],
|
|
140
231
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
target: config.ssr?.target ?? "node",
|
|
144
|
-
optimizeDeps: {
|
|
145
|
-
...config.ssr?.optimizeDeps,
|
|
146
|
-
include: config.ssr?.optimizeDeps?.include ?? [
|
|
147
|
-
"react",
|
|
148
|
-
"react-dom",
|
|
149
|
-
"react-server-dom-esm/client",
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
|
-
resolve: {
|
|
153
|
-
...config.ssr?.resolve,
|
|
154
|
-
externalConditions: config.ssr?.resolve?.externalConditions ?? [
|
|
155
|
-
"react-server",
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
},
|
|
232
|
+
define: define,
|
|
233
|
+
ssr: srrConfig,
|
|
159
234
|
// client build options
|
|
160
235
|
build: {
|
|
161
236
|
...config.build,
|
|
162
237
|
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
163
238
|
outDir: config.build?.outDir ?? join(userOptions.build.outDir, envDir),
|
|
164
239
|
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
165
|
-
copyPublicDir:
|
|
240
|
+
copyPublicDir:
|
|
241
|
+
typeof config.build?.copyPublicDir === "boolean"
|
|
242
|
+
? config.build?.copyPublicDir
|
|
243
|
+
: !ssr,
|
|
166
244
|
// modern browsers
|
|
167
245
|
target: config.build?.target ?? ["esnext"],
|
|
168
246
|
minify: minify,
|
|
@@ -194,7 +272,7 @@ export function resolveUserConfig({
|
|
|
194
272
|
...config,
|
|
195
273
|
root: root,
|
|
196
274
|
mode: mode,
|
|
197
|
-
base: userOptions.
|
|
275
|
+
base: userOptions.moduleBaseURL,
|
|
198
276
|
envPrefix: vitePrefix,
|
|
199
277
|
resolve: {
|
|
200
278
|
...config.resolve,
|
|
@@ -202,39 +280,8 @@ export function resolveUserConfig({
|
|
|
202
280
|
"react-server",
|
|
203
281
|
],
|
|
204
282
|
},
|
|
205
|
-
define:
|
|
206
|
-
|
|
207
|
-
[`process.env.${vitePrefix}SSR`]: `"1"`,
|
|
208
|
-
[`process.env.${vitePrefix}DEV`]: `"${mode === "development" ? "1" : "0"}"`,
|
|
209
|
-
[`process.env.${vitePrefix}PROD`]: `"${mode === "production" ? "1" : "0"}"`,
|
|
210
|
-
[`process.env.${vitePrefix}MODE`]: `"${mode}"`,
|
|
211
|
-
[`process.env.${vitePrefix}BASE_URL`]: `"${
|
|
212
|
-
userOptions.moduleBasePath === "" ||
|
|
213
|
-
userOptions.moduleBasePath === "/"
|
|
214
|
-
? "/"
|
|
215
|
-
: !userOptions.moduleBasePath.endsWith("/")
|
|
216
|
-
? userOptions.moduleBasePath + "/"
|
|
217
|
-
: userOptions.moduleBasePath
|
|
218
|
-
}"`,
|
|
219
|
-
},
|
|
220
|
-
ssr: {
|
|
221
|
-
...config.ssr,
|
|
222
|
-
target: config.ssr?.target ?? "node",
|
|
223
|
-
optimizeDeps: {
|
|
224
|
-
...config.ssr?.optimizeDeps,
|
|
225
|
-
include: config.ssr?.optimizeDeps?.include ?? [
|
|
226
|
-
"react",
|
|
227
|
-
"react-dom",
|
|
228
|
-
"react-server-dom-esm/client",
|
|
229
|
-
],
|
|
230
|
-
},
|
|
231
|
-
resolve: {
|
|
232
|
-
...config.ssr?.resolve,
|
|
233
|
-
externalConditions: config.ssr?.resolve?.externalConditions ?? [
|
|
234
|
-
"react-server",
|
|
235
|
-
],
|
|
236
|
-
},
|
|
237
|
-
},
|
|
283
|
+
define: define,
|
|
284
|
+
ssr: srrConfig,
|
|
238
285
|
// server build options
|
|
239
286
|
build: {
|
|
240
287
|
...config.build,
|
|
@@ -252,7 +299,7 @@ export function resolveUserConfig({
|
|
|
252
299
|
copyPublicDir:
|
|
253
300
|
typeof config.build?.copyPublicDir === "boolean"
|
|
254
301
|
? config.build?.copyPublicDir
|
|
255
|
-
:
|
|
302
|
+
: !ssr,
|
|
256
303
|
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
257
304
|
// Ensure CSS files are output to static directory
|
|
258
305
|
cssCodeSplit:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './plugin.js';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { resolveConfigDefine, resolveEnv } from "../config/resolveEnv.js";
|
|
3
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
4
|
+
import { userProjectRoot } from "../root.js";
|
|
5
|
+
const isBuild = process.argv[process.argv.length - 1] === "build";
|
|
6
|
+
const isPreview = process.argv.findIndex((arg) => arg === "preview") !== -1;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// Set up environment variables from .env files as early as possible
|
|
10
|
+
// This is to ensure that the env variables are available even in the config file,
|
|
11
|
+
// and you can use process.env to configure the plugin.
|
|
12
|
+
const cleanupInitialUserConfigEnv = resolveEnv(
|
|
13
|
+
process.env["NODE_ENV"] || (isBuild || isPreview ? "production" : "development"),
|
|
14
|
+
userProjectRoot,
|
|
15
|
+
DEFAULT_CONFIG.ENV_PREFIX
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This plugin can be used to set up the environment defined in the env file
|
|
20
|
+
* and the `define` clause in the vite config to be directly assigned to the process.env,
|
|
21
|
+
* making it available in workers, server components and plugin hooks like config, configureServer, etc.
|
|
22
|
+
*
|
|
23
|
+
* You can also set these variable in the package.json script like `VITE_PUBLIC_ORIGIN=https://example.com npm run build`
|
|
24
|
+
* The default ones like `VITE_DEV` etc, are set to the default values if not defined in the env file or the `define` clause.
|
|
25
|
+
*
|
|
26
|
+
* If they do end up in the build, the define clause replaces process.env.VITE_BASE_URL etc, same like it
|
|
27
|
+
* replaces `import.meta.env.BASE_URL`.
|
|
28
|
+
*
|
|
29
|
+
* While using node.process.env is dangerous as it may expose valuable information to the client, the define clause
|
|
30
|
+
* replaces them in the build so it's safe as long as you stick to simple stuff like const baseUrl = process.env.VITE_BASE_URL
|
|
31
|
+
* would be the same as writing const baseUrl = import.meta.env.BASE_URL. But this plugin doesn't enable that feature nor does
|
|
32
|
+
* it return any config, it just sets the process.env variables at a early momemt and deletes them after the build unless they were
|
|
33
|
+
* already set in the environment.
|
|
34
|
+
*
|
|
35
|
+
* This plugin will not override process.env variable that were previously set, and will remove any values that it did set after the bundle closes.
|
|
36
|
+
* ```example
|
|
37
|
+
* const config = {
|
|
38
|
+
* moduleBase: 'src',
|
|
39
|
+
* // loaded from either .env file or existing process.env, based on the NODE_ENV
|
|
40
|
+
* publicOrigin: process.env.VITE_PUBLIC_ORIGIN,
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export function envPlugin(): Plugin {
|
|
46
|
+
let cleanupEnv: (() => void) | undefined;
|
|
47
|
+
return {
|
|
48
|
+
name: "vite-plugin-react-server:env",
|
|
49
|
+
enforce: "pre",
|
|
50
|
+
config(config, { mode }) {
|
|
51
|
+
const invalidEnv =
|
|
52
|
+
(mode !== undefined && mode !== process.env.VITE_MODE) ||
|
|
53
|
+
(config.root !== undefined && config.root !== userProjectRoot);
|
|
54
|
+
if (invalidEnv) {
|
|
55
|
+
cleanupInitialUserConfigEnv();
|
|
56
|
+
}
|
|
57
|
+
// Clean up any previous env setup
|
|
58
|
+
const cleanupUserConfigEnv = invalidEnv
|
|
59
|
+
? resolveEnv(
|
|
60
|
+
mode || process.env.VITE_MODE,
|
|
61
|
+
config.root ?? userProjectRoot,
|
|
62
|
+
config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX
|
|
63
|
+
)
|
|
64
|
+
: cleanupInitialUserConfigEnv;
|
|
65
|
+
const cleanupUserConfig = resolveConfigDefine(config);
|
|
66
|
+
|
|
67
|
+
// Combine cleanup functions
|
|
68
|
+
cleanupEnv = () => {
|
|
69
|
+
cleanupUserConfig();
|
|
70
|
+
cleanupUserConfigEnv();
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
closeBundle() {
|
|
74
|
+
// Clean up environment variables when the bundle is closed
|
|
75
|
+
cleanupEnv?.();
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function toError(error: unknown): {
|
|
2
|
+
name: string;
|
|
3
|
+
message: string;
|
|
4
|
+
stack?: string;
|
|
5
|
+
} {
|
|
6
|
+
return error instanceof Error
|
|
7
|
+
? error
|
|
8
|
+
: typeof error === "object" && error !== null
|
|
9
|
+
? {
|
|
10
|
+
name: "name" in error ? String(error.name) : "Unknown Error",
|
|
11
|
+
message: "message" in error ? String(error.message) : "Unknown Error",
|
|
12
|
+
stack: "stack" in error ? String(error.stack) : undefined,
|
|
13
|
+
}
|
|
14
|
+
: {
|
|
15
|
+
name: "Unknown Error",
|
|
16
|
+
message: typeof error === "string" ? error : "Unknown Error",
|
|
17
|
+
stack: undefined,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { OutputAsset } from "rollup";
|
|
2
|
+
import type { ESBuildOptions, Plugin as VitePlugin } from "vite";
|
|
3
|
+
import { transformWithEsbuild } from "vite";
|
|
4
|
+
import { writeFile } from "node:fs/promises";
|
|
5
|
+
import { join, sep } from "node:path";
|
|
6
|
+
/**
|
|
7
|
+
* Bundling with vite may have some side effects, this plugin is a workaround to prevent
|
|
8
|
+
* the side effects from happening to the files we want to preserve. It's used as a plugin
|
|
9
|
+
* to build this plugin, but you can also use it as a standalone plugin for your projects to have
|
|
10
|
+
* the same effect.
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { filePreserverPlugin } from "vite-plugin-react-server/file-preserver";
|
|
14
|
+
*
|
|
15
|
+
* export default defineConfig({
|
|
16
|
+
* plugins: [filePreserverPlugin("utils/env")], // don't include the extension
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
* The typescript file will not be transformed by vite, only by esbuild, so you can preserve your import.meta.env
|
|
20
|
+
* and use it in your client boundary files.
|
|
21
|
+
*/
|
|
22
|
+
export function filePreserverPlugin(fileName: string | string[]): VitePlugin[] {
|
|
23
|
+
let sources: {
|
|
24
|
+
id: string;
|
|
25
|
+
originalCode: string;
|
|
26
|
+
transformedCode: string;
|
|
27
|
+
map: string;
|
|
28
|
+
}[] = [];
|
|
29
|
+
let pluginName =
|
|
30
|
+
typeof fileName === "string" ? fileName : fileName.slice(3).join("-");
|
|
31
|
+
let outDir: string = "dist";
|
|
32
|
+
let root: string = process.cwd();
|
|
33
|
+
let esbuildOptions: ESBuildOptions = {
|
|
34
|
+
jsxDev: false,
|
|
35
|
+
supported: { "import-meta": true },
|
|
36
|
+
target: "esnext",
|
|
37
|
+
format: "esm",
|
|
38
|
+
};
|
|
39
|
+
let shouldPreserve = Array.isArray(fileName)
|
|
40
|
+
? (id: string) => fileName.some((f) => id.includes(f))
|
|
41
|
+
: (id: string) => id.includes(fileName);
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
name: `vite:preserver-${pluginName}:post`,
|
|
45
|
+
enforce: "post",
|
|
46
|
+
apply: "build",
|
|
47
|
+
async transform(_code: string, id: string) {
|
|
48
|
+
if (!shouldPreserve(id)) return;
|
|
49
|
+
const normalId = id.replace(root + sep, "");
|
|
50
|
+
const found = sources.findIndex((s) => s.id === normalId);
|
|
51
|
+
if (found === -1) {
|
|
52
|
+
throw new Error(`Source not registered by pre hook for ${id}`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
code: sources[found].transformedCode,
|
|
56
|
+
map: sources[found].map,
|
|
57
|
+
id: sources[found].id,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
async writeBundle(_options, bundle) {
|
|
61
|
+
if (sources.length === 0) return;
|
|
62
|
+
const entries = Object.entries(bundle);
|
|
63
|
+
const mapEntries = entries.filter(
|
|
64
|
+
(entry): entry is [string, OutputAsset] => {
|
|
65
|
+
return (
|
|
66
|
+
entry[1].fileName.endsWith(".map") &&
|
|
67
|
+
shouldPreserve(entry[1].fileName)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
if (mapEntries.length === 0) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// even though we're returning the new source map, it might just write ;;;; to the file
|
|
75
|
+
for (const source of sources) {
|
|
76
|
+
for (const [fileName, outputAsset] of mapEntries) {
|
|
77
|
+
const ourMap = source.map;
|
|
78
|
+
const path = join(root, outDir, fileName);
|
|
79
|
+
if (outputAsset.source !== ourMap) {
|
|
80
|
+
await writeFile(path, ourMap);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: `vite:preserver-${pluginName}:pre`,
|
|
88
|
+
apply: "build",
|
|
89
|
+
enforce: "pre",
|
|
90
|
+
configResolved(config) {
|
|
91
|
+
outDir = config.build.outDir;
|
|
92
|
+
root = config.root;
|
|
93
|
+
esbuildOptions = config.esbuild || esbuildOptions;
|
|
94
|
+
},
|
|
95
|
+
async transform(code: string, id: string) {
|
|
96
|
+
if (!shouldPreserve(id)) return;
|
|
97
|
+
const found = sources.find((s) => s.id === id);
|
|
98
|
+
if (found) {
|
|
99
|
+
throw new Error(`Source already exists for ${id}`);
|
|
100
|
+
}
|
|
101
|
+
const result = await transformWithEsbuild(code, id, esbuildOptions);
|
|
102
|
+
const source = {
|
|
103
|
+
id: id.replace(root + sep, ""),
|
|
104
|
+
originalCode: code,
|
|
105
|
+
transformedCode: result.code,
|
|
106
|
+
map: JSON.stringify(result.map),
|
|
107
|
+
};
|
|
108
|
+
sources.push(source);
|
|
109
|
+
return {
|
|
110
|
+
id: source.id,
|
|
111
|
+
code: source.transformedCode,
|
|
112
|
+
map: source.map,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
}
|
|
@@ -76,14 +76,22 @@ export const createCssProps = ({
|
|
|
76
76
|
: {}),
|
|
77
77
|
} as CssContent<true>;
|
|
78
78
|
}
|
|
79
|
+
const joined = normalizedId.startsWith(moduleBasePath) ? normalizedId : join(moduleBasePath, normalizedId);
|
|
80
|
+
const moduleBaseHasTrailingSlash = moduleBaseURL.endsWith("/");
|
|
81
|
+
const joinedHasLeadingSlash = joined.startsWith("/");
|
|
79
82
|
const safeParseURL = (() => {
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
} catch (error) {
|
|
83
|
-
// if the url is not valid, we return the moduleBaseURL + the normalizedId
|
|
84
|
-
// dont make it a argument of join or it will mangle something like http:// into http:/
|
|
85
|
-
return moduleBaseURL + join(moduleBasePath, normalizedId);
|
|
83
|
+
if(joined.startsWith(moduleBaseHasTrailingSlash ? moduleBaseURL.slice(0, -1) : moduleBaseURL)) {
|
|
84
|
+
return joined;
|
|
86
85
|
}
|
|
86
|
+
try {
|
|
87
|
+
if (moduleBaseURL.includes("//")) {
|
|
88
|
+
// relative to moduleBaseURL
|
|
89
|
+
return new URL(joinedHasLeadingSlash ? joined.slice(1) : joined, moduleBaseURL).href;
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {}
|
|
92
|
+
// if the url is not valid, we return the moduleBaseURL + the normalizedId
|
|
93
|
+
// dont make it a argument of join or it will mangle something like http:// into http:/
|
|
94
|
+
return moduleBaseURL + (!moduleBaseHasTrailingSlash && !joinedHasLeadingSlash ? "/" : "") + (moduleBaseHasTrailingSlash ? joined.slice(1) : joined);
|
|
87
95
|
})();
|
|
88
96
|
// Default case
|
|
89
97
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { React, ReactDOMServer } from "../vendor.server.js";
|
|
1
|
+
import { React, ReactDOMServer } from "../vendor/vendor.server.js";
|
|
2
2
|
import type { CreateHandlerOptions, StreamMetrics } from "../types.js";
|
|
3
3
|
import { performance } from "node:perf_hooks";
|
|
4
4
|
export function createRscStream<
|
|
@@ -32,6 +32,6 @@ Stream:
|
|
|
32
32
|
`.trim();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function logMetrics(metrics: RenderMetrics) {
|
|
36
|
-
|
|
35
|
+
export function logMetrics(metrics: RenderMetrics, logger: {info: (message: string) => void} = console) {
|
|
36
|
+
logger.info(formatMetrics(metrics));
|
|
37
37
|
}
|
|
@@ -17,7 +17,7 @@ type GetRouteFilesError = {
|
|
|
17
17
|
export const getRouteFiles = async (
|
|
18
18
|
route: string,
|
|
19
19
|
autoDiscoveredFiles: AutoDiscoveredFiles,
|
|
20
|
-
userOptions: ResolvedUserOptions
|
|
20
|
+
userOptions: Pick<ResolvedUserOptions, "Page" | "props" | "moduleBasePath">
|
|
21
21
|
): Promise<GetRouteFilesSuccess | GetRouteFilesError> => {
|
|
22
22
|
if (autoDiscoveredFiles.urlMap.has(route)) {
|
|
23
23
|
const { page, props } = autoDiscoveredFiles.urlMap.get(route)!;
|
|
@@ -32,6 +32,7 @@ export const getRouteFiles = async (
|
|
|
32
32
|
return { type: "error", error };
|
|
33
33
|
}
|
|
34
34
|
if (!userOptions.props) {
|
|
35
|
+
autoDiscoveredFiles.urlMap.set(route, { page: Page, props: undefined });
|
|
35
36
|
return { type: "success", page: Page, props: undefined };
|
|
36
37
|
}
|
|
37
38
|
const {
|
|
@@ -43,5 +44,6 @@ export const getRouteFiles = async (
|
|
|
43
44
|
if (propsType === "error") {
|
|
44
45
|
return { type: "error", error: propsError };
|
|
45
46
|
}
|
|
47
|
+
autoDiscoveredFiles.urlMap.set(route, { page: Page, props });
|
|
46
48
|
return { type: "success", page: Page, props };
|
|
47
49
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Route and file handling
|
|
2
|
+
export * from "./getRouteFiles.js";
|
|
3
|
+
export * from "./resolvePage.js";
|
|
4
|
+
export * from "./resolveProps.js";
|
|
5
|
+
export * from "./resolvePageAndProps.js";
|
|
6
|
+
export * from "./requestInfo.js";
|
|
7
|
+
export * from "./requestToRoute.js";
|
|
8
|
+
|
|
9
|
+
// Configuration and options
|
|
10
|
+
export * from "./serializeUserOptions.js";
|
|
11
|
+
export * from "./cleanObject.js";
|
|
12
|
+
export * from "./inputNormalizer.js";
|
|
13
|
+
|
|
14
|
+
// CSS handling
|
|
15
|
+
export * from "./collectBundleManifestCss.js";
|
|
16
|
+
export * from "./collectManifestCss.js";
|
|
17
|
+
export * from "./collectViteModuleGraphCss.js";
|
|
18
|
+
export * from "./createCssProps.jsx";
|
|
19
|
+
|
|
20
|
+
// Stream and handler creation
|
|
21
|
+
export * from "./createRscStream.jsx";
|
|
22
|
+
export * from "./createHandler.js";
|
|
23
|
+
export * from "./createEventHandler.js";
|
|
24
|
+
|
|
25
|
+
// Metrics and monitoring
|
|
26
|
+
export * from "./formatMetrics.js";
|
|
27
|
+
export * from "./metrics.js";
|
|
28
|
+
|
|
29
|
+
// Manifest handling
|
|
30
|
+
export * from "./tryManifest.js";
|
|
31
|
+
export * from "./getBundleManifest.js";
|
|
32
|
+
|
|
33
|
+
// Module handling
|
|
34
|
+
export * from "./moduleRefs.js";
|
|
35
|
+
|
|
36
|
+
// Utility functions
|
|
37
|
+
export * from "./stashReturnValue.js";
|
|
38
|
+
export * from "./defaultFileWriter.js";
|