vite-plugin-react-server 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -76
- package/bin/patch.mjs +27 -20
- package/dist/_virtual/dynamic-import-helper.js +24 -0
- package/dist/_virtual/dynamic-import-helper.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -26
- package/dist/index.js.map +1 -1
- package/dist/package.json +24 -14
- package/dist/plugin/components.d.ts +1 -1
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +18 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +42 -21
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getCondition.d.ts +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +2 -2
- package/dist/plugin/config/getCondition.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/index.d.ts +0 -1
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscover.js +128 -0
- package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +109 -77
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +0 -1
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +6 -8
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
- package/dist/plugin/config/resolveUrlOption.js +37 -0
- package/dist/plugin/config/resolveUrlOption.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -132
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy.d.ts +7 -0
- package/dist/plugin/copy.d.ts.map +1 -0
- package/dist/plugin/copy.js +30 -0
- package/dist/plugin/css-collector-elements.d.ts +4 -0
- package/dist/plugin/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/css-collector-elements.js +19 -0
- package/dist/plugin/css-collector-elements.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +2 -8
- package/dist/plugin/css-collector.d.ts.map +1 -1
- package/dist/plugin/css-collector.js +9 -36
- package/dist/plugin/css-collector.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts +3 -0
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
- package/dist/plugin/helpers/cleanObject.js +47 -0
- package/dist/plugin/helpers/cleanObject.js.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js +44 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
- package/dist/plugin/helpers/createCssProps.d.ts +25 -0
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
- package/dist/plugin/helpers/createCssProps.js +57 -0
- package/dist/plugin/helpers/createCssProps.js.map +1 -0
- package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createEventHandler.js +36 -0
- package/dist/plugin/helpers/createEventHandler.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +7 -13
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +54 -96
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +12 -26
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +105 -51
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
- package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
- package/dist/plugin/helpers/defaultFileWriter.js +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +30 -22
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.js +36 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +38 -32
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.d.ts +11 -0
- package/dist/plugin/helpers/metrics.d.ts.map +1 -0
- package/dist/plugin/helpers/metrics.js +35 -0
- package/dist/plugin/helpers/metrics.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +182 -0
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.js +14 -0
- package/dist/plugin/helpers/tryManifest.d.ts +5 -3
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +16 -7
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/html.d.ts +2 -3
- package/dist/plugin/html.d.ts.map +1 -1
- package/dist/plugin/html.js +7 -1
- package/dist/plugin/html.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +3 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +98 -33
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts +57 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.development.js +81 -0
- package/dist/plugin/loader/css-loader.development.js.map +1 -0
- package/dist/plugin/loader/css-loader.production.d.ts +31 -0
- package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.production.js +45 -0
- package/dist/plugin/loader/css-loader.production.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +2 -0
- package/dist/plugin/loader/index.d.ts.map +1 -0
- package/dist/plugin/loader/index.js +1 -0
- package/dist/plugin/loader/plugin.d.ts +22 -0
- package/dist/plugin/loader/plugin.d.ts.map +1 -0
- package/dist/plugin/loader/plugin.js +27 -0
- package/dist/plugin/loader/react-loader.d.ts +3 -7
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +85 -30
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
- package/dist/plugin/loader/temporaryReferences.js +11 -0
- package/dist/plugin/loader/temporaryReferences.js.map +1 -0
- package/dist/plugin/moduleRefs.d.ts +7 -0
- package/dist/plugin/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/moduleRefs.js +17 -0
- package/dist/plugin/moduleRefs.js.map +1 -0
- package/dist/plugin/plugin.client.d.ts +3 -0
- package/dist/plugin/plugin.client.d.ts.map +1 -0
- package/dist/plugin/plugin.client.js +19 -0
- package/dist/plugin/plugin.client.js.map +1 -0
- package/dist/plugin/plugin.d.ts +1 -5
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +3 -9
- package/dist/plugin/plugin.server.d.ts +3 -0
- package/dist/plugin/plugin.server.d.ts.map +1 -0
- package/dist/plugin/plugin.server.js +28 -0
- package/dist/plugin/plugin.server.js.map +1 -0
- package/dist/plugin/preserver/plugin.js +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +1 -2
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +1 -19
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +60 -219
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +27 -0
- package/dist/plugin/react-client/server.d.ts.map +1 -0
- package/dist/plugin/react-client/server.js +197 -0
- package/dist/plugin/react-client/server.js.map +1 -0
- package/dist/plugin/react-server/index.d.ts +1 -2
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +1 -21
- package/dist/plugin/react-server/plugin.d.ts +0 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +60 -186
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts +9 -0
- package/dist/plugin/react-server/server.d.ts.map +1 -0
- package/dist/plugin/react-server/server.js +120 -0
- package/dist/plugin/react-server/server.js.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
- package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectRscContent.js +49 -0
- package/dist/plugin/react-static/collectRscContent.js.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.js +67 -0
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
- package/dist/plugin/react-static/fileWriter.d.ts +23 -0
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
- package/dist/plugin/react-static/fileWriter.js +65 -0
- package/dist/plugin/react-static/fileWriter.js.map +1 -0
- package/dist/plugin/react-static/plugin.d.ts +15 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +248 -149
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +3 -0
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPage.js +116 -0
- package/dist/plugin/react-static/renderPage.js.map +1 -0
- package/dist/plugin/react-static/renderPages.d.ts +3 -0
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPages.js +125 -0
- package/dist/plugin/react-static/renderPages.js.map +1 -0
- package/dist/plugin/react-static/renderStreams.d.ts +26 -0
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
- package/dist/plugin/react-static/renderStreams.js +27 -0
- package/dist/plugin/react-static/renderStreams.js.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
- package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
- package/dist/plugin/react-static/streamHandler.d.ts +2 -0
- package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
- package/dist/plugin/react-static/streamHandler.js +1 -0
- package/dist/plugin/react-static/types.d.ts +11 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -1
- package/dist/plugin/resolvePage.d.ts +26 -9
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +41 -39
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/resolveProps.d.ts +40 -7
- package/dist/plugin/resolveProps.d.ts.map +1 -1
- package/dist/plugin/resolveProps.js +100 -75
- package/dist/plugin/resolveProps.js.map +1 -1
- package/dist/plugin/root.d.ts +1 -0
- package/dist/plugin/root.d.ts.map +1 -1
- package/dist/plugin/root.js +1 -0
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/index.d.ts +2 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +2 -1
- package/dist/plugin/transformer/plugin.client.d.ts +4 -0
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.client.js +83 -0
- package/dist/plugin/transformer/plugin.client.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts +1 -27
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +3 -87
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +4 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.server.js +76 -0
- package/dist/plugin/transformer/plugin.server.js.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
- package/dist/plugin/types/css-tracking.d.ts +6 -0
- package/dist/plugin/types/css-tracking.d.ts.map +1 -0
- package/dist/plugin/types/css-tracking.js +1 -0
- package/dist/plugin/types.d.ts +372 -86
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/vendor.client.d.ts +4 -0
- package/dist/plugin/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor.client.js +16 -0
- package/dist/plugin/vendor.client.js.map +1 -0
- package/dist/plugin/vendor.server.d.ts +4 -0
- package/dist/plugin/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor.server.js +16 -0
- package/dist/plugin/vendor.server.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +25 -7
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +108 -33
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +3 -17
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +12 -5
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +87 -84
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/types.d.ts +18 -0
- package/dist/plugin/worker/html/types.d.ts.map +1 -0
- package/dist/plugin/worker/html/types.js +1 -0
- package/dist/plugin/worker/registerLoaders.d.ts +9 -0
- package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
- package/dist/plugin/worker/registerLoaders.js +45 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/handleRender.js +147 -0
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +47 -112
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +73 -2
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +40 -3
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +3 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
- package/dist/plugin/worker/sendMessage.js +48 -0
- package/dist/plugin/worker/types.d.ts +218 -76
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/plugin/components.ts +1 -1
- package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
- package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
- package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
- package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
- package/plugin/config/defaults.tsx +38 -29
- package/plugin/config/getCondition.ts +7 -3
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/index.ts +0 -1
- package/plugin/config/resolveAutoDiscover.ts +177 -0
- package/plugin/config/resolveOptions.ts +220 -118
- package/plugin/config/resolvePages.ts +5 -7
- package/plugin/config/resolveUrlOption.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +116 -166
- package/plugin/copy.ts +39 -0
- package/plugin/css-collector-elements.tsx +21 -0
- package/plugin/css-collector.tsx +20 -53
- package/plugin/helpers/cleanObject.ts +50 -0
- package/plugin/helpers/collectBundleManifestCss.ts +160 -0
- package/plugin/helpers/collectManifestCss.ts +61 -0
- package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
- package/plugin/helpers/createCssProps.tsx +85 -0
- package/plugin/helpers/createEventHandler.ts +44 -0
- package/plugin/helpers/createHandler.ts +57 -126
- package/plugin/helpers/createRscStream.tsx +156 -0
- package/plugin/helpers/defaultFileWriter.ts +0 -0
- package/plugin/helpers/getBundleManifest.ts +42 -37
- package/plugin/helpers/getRouteFiles.ts +47 -0
- package/plugin/helpers/inputNormalizer.ts +16 -10
- package/plugin/helpers/metrics.ts +64 -0
- package/plugin/helpers/resolvePageAndProps.ts +81 -0
- package/plugin/helpers/serializeUserOptions.ts +209 -0
- package/plugin/helpers/stashReturnValue.ts +16 -0
- package/plugin/helpers/tryManifest.ts +35 -18
- package/plugin/html.tsx +14 -3
- package/plugin/index.ts +5 -2
- package/plugin/loader/createBuildLoader.ts +152 -47
- package/plugin/loader/css-loader.development.ts +157 -0
- package/plugin/loader/css-loader.production.ts +86 -0
- package/plugin/loader/index.ts +1 -0
- package/plugin/loader/plugin.ts +33 -0
- package/plugin/loader/react-loader.ts +109 -41
- package/plugin/loader/temporaryReferences.ts +3 -0
- package/plugin/moduleRefs.ts +11 -0
- package/plugin/plugin.client.ts +12 -0
- package/plugin/plugin.server.ts +25 -0
- package/plugin/plugin.ts +5 -9
- package/plugin/preserver/plugin.ts +1 -1
- package/plugin/react-client/index.ts +1 -12
- package/plugin/react-client/plugin.ts +70 -259
- package/plugin/react-client/server.ts +276 -0
- package/plugin/react-server/index.ts +1 -14
- package/plugin/react-server/plugin.ts +69 -220
- package/plugin/react-server/server.ts +128 -0
- package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
- package/plugin/react-static/collectRscContent.ts +77 -0
- package/plugin/react-static/configurePreviewServer.ts +68 -0
- package/plugin/react-static/fileWriter.ts +103 -0
- package/plugin/react-static/plugin.ts +308 -181
- package/plugin/react-static/renderPage.ts +151 -0
- package/plugin/react-static/renderPages.ts +154 -0
- package/plugin/react-static/renderStreams.ts +48 -0
- package/plugin/react-static/rscToHtmlStream.ts +85 -0
- package/plugin/react-static/streamHandler.ts +0 -0
- package/plugin/react-static/types.ts +10 -0
- package/plugin/resolvePage.ts +67 -57
- package/plugin/resolveProps.ts +148 -104
- package/plugin/root.ts +1 -1
- package/plugin/transformer/index.ts +2 -1
- package/plugin/transformer/plugin.client.ts +109 -0
- package/plugin/transformer/plugin.server.ts +98 -0
- package/plugin/transformer/plugin.ts +2 -115
- package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
- package/plugin/types/css-tracking.ts +5 -0
- package/plugin/types/react-server-dom-esm.d.ts +54 -0
- package/plugin/types.ts +508 -97
- package/plugin/vendor.client.ts +12 -0
- package/plugin/vendor.server.ts +12 -0
- package/plugin/worker/createWorker.ts +158 -53
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
- package/plugin/worker/html/html-worker.development.tsx +5 -75
- package/plugin/worker/html/html-worker.production.tsx +18 -7
- package/plugin/worker/html/messageHandler.tsx +126 -0
- package/plugin/worker/html/types.ts +19 -0
- package/plugin/worker/registerLoaders.ts +54 -0
- package/plugin/worker/rsc/handleRender.ts +180 -0
- package/plugin/worker/rsc/messageHandler.tsx +58 -132
- package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
- package/plugin/worker/rsc/state.ts +79 -2
- package/plugin/worker/sendMessage.ts +49 -0
- package/plugin/worker/types.ts +299 -100
- package/scripts/check-react-version.mjs +60 -48
- package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
- package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
- package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
- package/tsconfig.json +7 -2
- package/dist/plugin/assertServerCondition.d.ts +0 -6
- package/dist/plugin/assertServerCondition.d.ts.map +0 -1
- package/dist/plugin/assertServerCondition.js +0 -13
- package/dist/plugin/checkFilesExist.d.ts +0 -3
- package/dist/plugin/checkFilesExist.d.ts.map +0 -1
- package/dist/plugin/checkFilesExist.js +0 -67
- package/dist/plugin/checkFilesExist.js.map +0 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
- package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
- package/dist/plugin/collect-manifest-client-files.js +0 -131
- package/dist/plugin/collect-manifest-client-files.js.map +0 -1
- package/dist/plugin/config/getWorkerPath.d.ts +0 -2
- package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
- package/dist/plugin/config/getWorkerPath.js +0 -4
- package/dist/plugin/copy-dir.d.ts +0 -4
- package/dist/plugin/copy-dir.d.ts.map +0 -1
- package/dist/plugin/copy-dir.js +0 -25
- package/dist/plugin/copy-dir.js.map +0 -1
- package/dist/plugin/css-collector-inline.d.ts +0 -10
- package/dist/plugin/css-collector-inline.d.ts.map +0 -1
- package/dist/plugin/css-collector-inline.js +0 -55
- package/dist/plugin/css-collector-inline.js.map +0 -1
- package/dist/plugin/loader/css-loader.d.ts +0 -16
- package/dist/plugin/loader/css-loader.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.js +0 -70
- package/dist/plugin/loader/css-loader.js.map +0 -1
- package/dist/plugin/react-client/index.js.map +0 -1
- package/dist/plugin/react-server/index.js.map +0 -1
- package/dist/plugin/worker/html/renderPages.d.ts +0 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
- package/dist/plugin/worker/html/renderPages.js +0 -241
- package/dist/plugin/worker/html/renderPages.js.map +0 -1
- package/plugin/assertServerCondition.ts +0 -12
- package/plugin/checkFilesExist.ts +0 -66
- package/plugin/collect-manifest-client-files.ts +0 -167
- package/plugin/config/getWorkerPath.ts +0 -5
- package/plugin/copy-dir.ts +0 -27
- package/plugin/css-collector-inline.tsx +0 -60
- package/plugin/helpers/createRscStream.ts +0 -109
- package/plugin/loader/css-loader.ts +0 -94
- package/plugin/worker/html/messageHandler.ts +0 -130
- package/plugin/worker/html/renderPages.ts +0 -293
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { ResolvedConfig, ViteDevServer } from "vite";
|
|
2
|
+
import type {
|
|
3
|
+
AutoDiscoveredFiles,
|
|
4
|
+
ResolvedUserOptions,
|
|
5
|
+
} from "../types.js";
|
|
6
|
+
import { cleanObject } from "./cleanObject.js";
|
|
7
|
+
|
|
8
|
+
// Common non-serializable functions in Vite's resolved config
|
|
9
|
+
const VITE_NON_SERIALIZABLE_FUNCTIONS = new Set([
|
|
10
|
+
"renderChunk",
|
|
11
|
+
"buildStart",
|
|
12
|
+
"buildEnd",
|
|
13
|
+
"watchChange",
|
|
14
|
+
"resolveId",
|
|
15
|
+
"config",
|
|
16
|
+
"output[].entryFileNames",
|
|
17
|
+
"output[].chunkFileNames",
|
|
18
|
+
"output[].assetFileNames",
|
|
19
|
+
"transform",
|
|
20
|
+
"handler",
|
|
21
|
+
"configureServer",
|
|
22
|
+
"shouldTransformCachedModule",
|
|
23
|
+
"generateBundle",
|
|
24
|
+
"renderStart",
|
|
25
|
+
"writeBundle",
|
|
26
|
+
"hotUpdate",
|
|
27
|
+
"configResolved",
|
|
28
|
+
"configurePreviewServer",
|
|
29
|
+
"handleHotUpdate",
|
|
30
|
+
"load",
|
|
31
|
+
"augmentChunkHash",
|
|
32
|
+
"closeBundle",
|
|
33
|
+
"entryFileNames",
|
|
34
|
+
"assetFileNames",
|
|
35
|
+
"chunkFileNames",
|
|
36
|
+
"createEnvironment",
|
|
37
|
+
"sourcemapIgnoreList",
|
|
38
|
+
"assetsInclude",
|
|
39
|
+
"info",
|
|
40
|
+
"warn",
|
|
41
|
+
"warnOnce",
|
|
42
|
+
"error",
|
|
43
|
+
"clearScreen",
|
|
44
|
+
"hasErrorLogged",
|
|
45
|
+
"set",
|
|
46
|
+
"plugins",
|
|
47
|
+
"getSortedPlugins",
|
|
48
|
+
"getSortedPluginHooks",
|
|
49
|
+
"createResolver",
|
|
50
|
+
"fsDenyGlob",
|
|
51
|
+
// Nested plugin functions
|
|
52
|
+
"plugins[].renderChunk",
|
|
53
|
+
"plugins[].buildStart",
|
|
54
|
+
"plugins[].buildEnd",
|
|
55
|
+
"plugins[].watchChange",
|
|
56
|
+
"plugins[].resolveId",
|
|
57
|
+
"plugins[].config",
|
|
58
|
+
"plugins[].transform",
|
|
59
|
+
"plugins[].handler",
|
|
60
|
+
"plugins[].configureServer",
|
|
61
|
+
"plugins[].shouldTransformCachedModule",
|
|
62
|
+
"plugins[].generateBundle",
|
|
63
|
+
"plugins[].renderStart",
|
|
64
|
+
"plugins[].writeBundle",
|
|
65
|
+
"plugins[].hotUpdate",
|
|
66
|
+
"plugins[].configResolved",
|
|
67
|
+
"plugins[].configurePreviewServer",
|
|
68
|
+
"plugins[].handleHotUpdate",
|
|
69
|
+
"plugins[].load",
|
|
70
|
+
"plugins[].augmentChunkHash",
|
|
71
|
+
"plugins[].closeBundle",
|
|
72
|
+
"plugins[].entryFileNames",
|
|
73
|
+
"plugins[].assetFileNames",
|
|
74
|
+
"plugins[].chunkFileNames",
|
|
75
|
+
"plugins[].createEnvironment",
|
|
76
|
+
"plugins[].sourcemapIgnoreList",
|
|
77
|
+
"plugins[].assetsInclude",
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
// Common non-serializable functions in our plugin's options
|
|
81
|
+
const PLUGIN_NON_SERIALIZABLE_FUNCTIONS = new Set([
|
|
82
|
+
"Page",
|
|
83
|
+
"props",
|
|
84
|
+
"normalizer",
|
|
85
|
+
"CssCollector",
|
|
86
|
+
"Html",
|
|
87
|
+
"onEvent",
|
|
88
|
+
"onMetrics",
|
|
89
|
+
"build.entryFile",
|
|
90
|
+
"build.chunkFile",
|
|
91
|
+
"build.assetFile",
|
|
92
|
+
"build.pages",
|
|
93
|
+
"autoDiscover",
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
// Helper function to serialize RegExp objects
|
|
97
|
+
function serializeRegExp(regex: RegExp) {
|
|
98
|
+
return {
|
|
99
|
+
source: regex.source,
|
|
100
|
+
flags: regex.flags,
|
|
101
|
+
__isRegExp: true
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Helper function to deserialize RegExp objects
|
|
106
|
+
export function deserializeRegExp(obj: any): any {
|
|
107
|
+
if (obj && obj.__isRegExp) {
|
|
108
|
+
return new RegExp(obj.source, obj.flags);
|
|
109
|
+
}
|
|
110
|
+
if (Array.isArray(obj)) {
|
|
111
|
+
return obj.map(deserializeRegExp);
|
|
112
|
+
}
|
|
113
|
+
if (obj && typeof obj === 'object') {
|
|
114
|
+
const result: any = {};
|
|
115
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
116
|
+
result[key] = deserializeRegExp(value);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
return obj;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Helper function to recursively process objects for serialization
|
|
124
|
+
export function processForSerialization(obj: any): any {
|
|
125
|
+
if (obj instanceof RegExp) {
|
|
126
|
+
return serializeRegExp(obj);
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(obj)) {
|
|
129
|
+
return obj.map(processForSerialization);
|
|
130
|
+
}
|
|
131
|
+
if (obj && typeof obj === 'object') {
|
|
132
|
+
const result: any = {};
|
|
133
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
134
|
+
result[key] = processForSerialization(value);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
return obj;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function serializeResolvedConfig<T extends ResolvedConfig>(
|
|
142
|
+
config: T,
|
|
143
|
+
knownNonSerializableFunctions: Set<string> = VITE_NON_SERIALIZABLE_FUNCTIONS
|
|
144
|
+
) {
|
|
145
|
+
const {
|
|
146
|
+
getSortedPluginHooks,
|
|
147
|
+
getSortedPlugins,
|
|
148
|
+
assetsInclude,
|
|
149
|
+
// extract known vite function properties
|
|
150
|
+
...handlerOptions
|
|
151
|
+
} = config;
|
|
152
|
+
|
|
153
|
+
// Clean the object to remove non-serializable properties and process RegExp objects
|
|
154
|
+
return processForSerialization(cleanObject(handlerOptions, knownNonSerializableFunctions));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// For Vite's config
|
|
158
|
+
export const serializedDevServerConfig = <T extends ViteDevServer["config"]>(
|
|
159
|
+
config: T,
|
|
160
|
+
customNonSerializableFunctions: Set<string> = PLUGIN_NON_SERIALIZABLE_FUNCTIONS
|
|
161
|
+
) => {
|
|
162
|
+
const {
|
|
163
|
+
getSortedPluginHooks,
|
|
164
|
+
getSortedPlugins,
|
|
165
|
+
assetsInclude,
|
|
166
|
+
build,
|
|
167
|
+
...handlerOptions
|
|
168
|
+
} = config;
|
|
169
|
+
return processForSerialization(cleanObject(
|
|
170
|
+
handlerOptions,
|
|
171
|
+
customNonSerializableFunctions
|
|
172
|
+
));
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// For your own options (if you need custom non-serializable functions)
|
|
176
|
+
export const serializedOptions = <T extends ResolvedUserOptions>(
|
|
177
|
+
userOptions: T,
|
|
178
|
+
autoDiscoveredFiles: AutoDiscoveredFiles,
|
|
179
|
+
customNonSerializableFunctions: Set<string> = PLUGIN_NON_SERIALIZABLE_FUNCTIONS
|
|
180
|
+
) => {
|
|
181
|
+
const {
|
|
182
|
+
Page,
|
|
183
|
+
props,
|
|
184
|
+
normalizer,
|
|
185
|
+
CssCollector,
|
|
186
|
+
Html,
|
|
187
|
+
onEvent,
|
|
188
|
+
onMetrics,
|
|
189
|
+
build,
|
|
190
|
+
autoDiscover,
|
|
191
|
+
...handlerOptions
|
|
192
|
+
} = userOptions;
|
|
193
|
+
const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build;
|
|
194
|
+
const result = {
|
|
195
|
+
...handlerOptions,
|
|
196
|
+
build: {
|
|
197
|
+
...buildOptions,
|
|
198
|
+
pages: autoDiscoveredFiles
|
|
199
|
+
? Array.from(autoDiscoveredFiles.urlMap.keys())
|
|
200
|
+
: [],
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// Clean the object to remove non-serializable properties and process RegExp objects
|
|
205
|
+
return processForSerialization(cleanObject(
|
|
206
|
+
result,
|
|
207
|
+
customNonSerializableFunctions
|
|
208
|
+
));
|
|
209
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const stashedReturnValue = new Map<string, any>();
|
|
2
|
+
export const stashReturnValue = <FN extends (...args: any[]) => unknown>(
|
|
3
|
+
fn: FN
|
|
4
|
+
): FN => {
|
|
5
|
+
return ((...args: Parameters<FN>): ReturnType<FN> => {
|
|
6
|
+
const id = args
|
|
7
|
+
.map((arg) =>!arg ? '' : typeof arg === "string" ? arg : typeof arg === "object" && 'id' in arg ? arg.id : '')
|
|
8
|
+
.join("_");
|
|
9
|
+
if (stashedReturnValue.has(id)) {
|
|
10
|
+
return stashedReturnValue.get(id);
|
|
11
|
+
}
|
|
12
|
+
const result = fn(...args);
|
|
13
|
+
stashedReturnValue.set(id, result);
|
|
14
|
+
return result as never;
|
|
15
|
+
}) as FN;
|
|
16
|
+
};
|
|
@@ -1,39 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
|
|
3
3
|
import type { Manifest } from "vite";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
4
5
|
|
|
5
|
-
type TryManifestOptions<SSR extends boolean> = {
|
|
6
|
+
type TryManifestOptions<SSR extends boolean = false> = {
|
|
6
7
|
root: string;
|
|
7
8
|
outDir: string;
|
|
8
9
|
ssrManifest?: SSR;
|
|
10
|
+
preserveModulesRoot?: string;
|
|
11
|
+
manifestPath?: string | undefined;
|
|
9
12
|
};
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const stashedManifests: Map<string, any> = new Map();
|
|
15
|
+
|
|
16
|
+
export async function tryManifest<SSR extends boolean>(
|
|
17
|
+
options: TryManifestOptions<SSR>
|
|
18
|
+
): Promise<
|
|
19
|
+
| {
|
|
20
|
+
type: "success";
|
|
21
|
+
manifest: SSR extends true ? Record<string, string[]> : Manifest;
|
|
22
|
+
error?: never;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
type: "error";
|
|
26
|
+
error: Error;
|
|
27
|
+
manifest?: never;
|
|
28
|
+
}> {
|
|
29
|
+
if (stashedManifests.has(options.outDir)) {
|
|
30
|
+
return {
|
|
31
|
+
type: "success",
|
|
32
|
+
manifest: stashedManifests.get(options.outDir),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const localSsrManifestPath = !options.ssrManifest ? undefined : options.manifestPath ? options.manifestPath : join('.vite', 'ssr-manifest.json');
|
|
36
|
+
const localManifestPath = options.ssrManifest ? undefined : options.manifestPath ? options.manifestPath : join('.vite', 'manifest.json');
|
|
20
37
|
const manifestPath = resolve(
|
|
21
38
|
options.root,
|
|
22
39
|
options.outDir,
|
|
23
|
-
|
|
24
|
-
options.ssrManifest ? "ssr-manifest.json" : "manifest.json"
|
|
40
|
+
options.ssrManifest ? localSsrManifestPath as string : localManifestPath as string
|
|
25
41
|
);
|
|
26
42
|
try {
|
|
27
|
-
const result=
|
|
43
|
+
const result = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
44
|
+
stashedManifests.set(options.outDir, result);
|
|
28
45
|
return {
|
|
29
46
|
type: "success",
|
|
30
47
|
manifest: result,
|
|
31
|
-
}
|
|
48
|
+
};
|
|
32
49
|
} catch (e) {
|
|
33
|
-
console.
|
|
50
|
+
console.trace("No manifest found", manifestPath);
|
|
34
51
|
return {
|
|
35
52
|
type: "error",
|
|
36
53
|
error: e as Error,
|
|
37
|
-
}
|
|
54
|
+
};
|
|
38
55
|
}
|
|
39
56
|
}
|
package/plugin/html.tsx
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
import type { HtmlProps } from "./types.js";
|
|
3
|
+
import { CssCollectorElements } from "./css-collector-elements.js";
|
|
4
|
+
export const Html = ({
|
|
5
|
+
children,
|
|
6
|
+
CssCollector,
|
|
7
|
+
cssFiles,
|
|
8
|
+
globalCss,
|
|
9
|
+
}: React.PropsWithChildren<HtmlProps>) => (
|
|
3
10
|
<html>
|
|
4
|
-
<head
|
|
11
|
+
<head>
|
|
12
|
+
<CssCollectorElements cssFiles={globalCss} />
|
|
13
|
+
</head>
|
|
5
14
|
<body>
|
|
6
|
-
<div id="root"
|
|
15
|
+
<CssCollector as={"div"} id="root" cssFiles={cssFiles}>
|
|
16
|
+
{children}
|
|
17
|
+
</CssCollector>
|
|
7
18
|
</body>
|
|
8
19
|
</html>
|
|
9
20
|
);
|
package/plugin/index.ts
CHANGED
|
@@ -1,67 +1,172 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import type { PluginContext } from "rollup";
|
|
3
2
|
import type { ResolvedUserConfig, ResolvedUserOptions } from "../../server.js";
|
|
4
3
|
import type { Manifest } from "vite";
|
|
5
|
-
import {
|
|
4
|
+
import { getModuleRef } from "../moduleRefs.js";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import type { OutputBundle } from "rollup";
|
|
7
|
+
import { temporaryReferences } from "./temporaryReferences.js";
|
|
6
8
|
|
|
7
9
|
export interface BuildLoaderOptions {
|
|
8
|
-
root: string;
|
|
9
|
-
pluginContext: PluginContext;
|
|
10
10
|
userConfig: ResolvedUserConfig;
|
|
11
11
|
userOptions: ResolvedUserOptions;
|
|
12
12
|
serverManifest: Manifest;
|
|
13
13
|
clientManifest: Manifest;
|
|
14
|
+
staticManifest: Manifest;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Creates a loader function for handling module resolution during build.
|
|
19
|
+
*
|
|
20
|
+
* The loader handles the following strategy:
|
|
21
|
+
* - Just load any file from any manifest we can find in the order of client, server, static
|
|
22
|
+
* - Ideally the buildLoader is only used form loading pages, props and inline css modules
|
|
23
|
+
* -
|
|
24
|
+
*
|
|
25
|
+
* During build:
|
|
26
|
+
* - We use the manifest information to get module exports
|
|
27
|
+
* - The manifest contains the transformed modules with their exports
|
|
28
|
+
* - We store the module in temporaryReferences for later use
|
|
29
|
+
*
|
|
30
|
+
* @param options.root - The project root directory
|
|
31
|
+
* @param options.pluginContext - The Rollup plugin context
|
|
32
|
+
* @param options.userConfig - Resolved user configuration
|
|
33
|
+
* @param options.userOptions - Resolved user options
|
|
34
|
+
* @param options.serverManifest - Vite server manifest
|
|
35
|
+
* @param options.clientManifest - Vite client manifest
|
|
36
|
+
* @param options.options - Additional options including temporaryReferences
|
|
37
|
+
*
|
|
38
|
+
* @returns A loader function that resolves module paths to their exports
|
|
39
|
+
*/
|
|
40
|
+
export async function createBuildLoader(
|
|
41
|
+
{
|
|
42
|
+
userOptions,
|
|
43
|
+
serverManifest,
|
|
44
|
+
clientManifest,
|
|
45
|
+
staticManifest,
|
|
46
|
+
}: BuildLoaderOptions,
|
|
47
|
+
bundle: OutputBundle
|
|
48
|
+
) {
|
|
49
|
+
const manifestKeys = Object.keys(serverManifest);
|
|
50
|
+
if (!manifestKeys.length) {
|
|
51
|
+
throw new Error("Server manifest is empty");
|
|
52
|
+
}
|
|
29
53
|
return async function buildLoader(id: string) {
|
|
30
|
-
const [
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
const [withoutQuery, query] = id.split("?", 2);
|
|
55
|
+
const [, normalizedValue] = userOptions.normalizer(withoutQuery);
|
|
56
|
+
const moduleRef = getModuleRef(id);
|
|
57
|
+
// Check if we have a temporary reference (cached module)
|
|
58
|
+
if (temporaryReferences?.has(moduleRef)) {
|
|
59
|
+
const mod = temporaryReferences.get(moduleRef);
|
|
60
|
+
if (typeof mod === "object" && mod !== null && "error" in mod) {
|
|
61
|
+
// ignore it
|
|
62
|
+
} else {
|
|
63
|
+
return mod;
|
|
64
|
+
}
|
|
33
65
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
// For inline modules, handle them directly
|
|
69
|
+
if (query === "inline") {
|
|
70
|
+
// Then check server manifest
|
|
71
|
+
const serverChunk =
|
|
72
|
+
bundle[serverManifest[normalizedValue]?.file] ??
|
|
73
|
+
bundle[staticManifest[normalizedValue]?.file] ??
|
|
74
|
+
bundle[clientManifest[normalizedValue]?.file] ??
|
|
75
|
+
bundle[withoutQuery];
|
|
76
|
+
if (serverChunk) {
|
|
77
|
+
if (serverChunk.type === "asset") {
|
|
78
|
+
return { default: serverChunk.source };
|
|
79
|
+
} else if ("code" in serverChunk) {
|
|
80
|
+
return { default: serverChunk.code };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// If not found in either manifest, try reading the file directly
|
|
85
|
+
const module = {
|
|
86
|
+
default: await readFile(
|
|
87
|
+
join(
|
|
88
|
+
userOptions.projectRoot,
|
|
89
|
+
userOptions.build.outDir,
|
|
90
|
+
userOptions.build.static,
|
|
91
|
+
normalizedValue
|
|
92
|
+
),
|
|
93
|
+
"utf-8"
|
|
94
|
+
),
|
|
95
|
+
};
|
|
96
|
+
temporaryReferences?.set(moduleRef, module);
|
|
97
|
+
return module;
|
|
98
|
+
}
|
|
99
|
+
const clientEntry = clientManifest[normalizedValue];
|
|
100
|
+
if (clientEntry) {
|
|
101
|
+
const module = await import(
|
|
102
|
+
join(
|
|
103
|
+
userOptions.projectRoot,
|
|
104
|
+
userOptions.build.outDir,
|
|
105
|
+
userOptions.build.client,
|
|
106
|
+
clientEntry.file
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
console.warn(
|
|
110
|
+
"client module used in buildLoader, consider making this available in the server manifest",
|
|
111
|
+
module
|
|
112
|
+
);
|
|
113
|
+
temporaryReferences?.set(moduleRef, module);
|
|
114
|
+
return module;
|
|
43
115
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
116
|
+
const bundleEntry = bundle[withoutQuery];
|
|
117
|
+
if (bundleEntry) {
|
|
118
|
+
// Load the module
|
|
119
|
+
const module = await import(
|
|
120
|
+
join(
|
|
121
|
+
userOptions.projectRoot,
|
|
122
|
+
userOptions.build.outDir,
|
|
123
|
+
userOptions.build.server,
|
|
124
|
+
bundleEntry.fileName
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
temporaryReferences?.set(moduleRef, module);
|
|
55
128
|
}
|
|
56
|
-
|
|
57
|
-
|
|
129
|
+
// Try to resolve the module using Vite's resolution
|
|
130
|
+
const serverEntry = serverManifest[normalizedValue];
|
|
131
|
+
if (serverEntry) {
|
|
132
|
+
// Load the module
|
|
133
|
+
const module = await import(
|
|
134
|
+
join(
|
|
135
|
+
userOptions.projectRoot,
|
|
136
|
+
userOptions.build.outDir,
|
|
137
|
+
userOptions.build.server,
|
|
138
|
+
serverEntry.file
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
temporaryReferences?.set(moduleRef, module);
|
|
142
|
+
return module;
|
|
58
143
|
}
|
|
59
|
-
|
|
60
|
-
|
|
144
|
+
// try static manifest
|
|
145
|
+
const staticEntry = staticManifest[normalizedValue];
|
|
146
|
+
if (staticEntry) {
|
|
147
|
+
const module = await import(
|
|
148
|
+
join(
|
|
149
|
+
userOptions.projectRoot,
|
|
150
|
+
userOptions.build.outDir,
|
|
151
|
+
userOptions.build.static,
|
|
152
|
+
staticEntry.file
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
console.warn(
|
|
156
|
+
"static module used in buildLoader, consider making this available in the server manifest",
|
|
157
|
+
module
|
|
158
|
+
);
|
|
159
|
+
temporaryReferences?.set(moduleRef, module);
|
|
160
|
+
return module;
|
|
61
161
|
}
|
|
62
|
-
|
|
63
|
-
|
|
162
|
+
throw new Error(`Module ${normalizedValue} not found`);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
const emptyExports = {
|
|
165
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
166
|
+
id: id,
|
|
167
|
+
};
|
|
168
|
+
temporaryReferences?.set(moduleRef, emptyExports);
|
|
169
|
+
return emptyExports;
|
|
64
170
|
}
|
|
65
|
-
throw new Error(`Module not found: ${id}`);
|
|
66
171
|
};
|
|
67
172
|
}
|