@shuvi/platform-web 0.0.1-rc.34 → 1.0.0-rc.2
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/esm/shared/appTypes.d.ts +15 -0
- package/esm/shared/appTypes.js +1 -0
- package/esm/shared/configTypes.d.ts +14 -0
- package/esm/shared/configTypes.js +1 -0
- package/esm/shared/index.d.ts +5 -0
- package/esm/shared/index.js +5 -0
- package/esm/shared/renderTypes.d.ts +44 -0
- package/esm/shared/renderTypes.js +1 -0
- package/esm/shared/routeTypes.d.ts +47 -0
- package/esm/shared/routeTypes.js +1 -0
- package/esm/shared/serverTypes.d.ts +6 -0
- package/esm/shared/serverTypes.js +1 -0
- package/esm/shuvi-app/app/client.d.ts +2 -0
- package/esm/shuvi-app/app/client.js +125 -0
- package/esm/shuvi-app/app/server.d.ts +2 -0
- package/esm/shuvi-app/app/server.js +67 -0
- package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.d.ts +0 -0
- package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.js +2 -1
- package/esm/shuvi-app/entry/client/app.d.ts +2 -0
- package/esm/shuvi-app/entry/client/app.js +57 -0
- package/esm/shuvi-app/entry/client/index.d.ts +2 -0
- package/esm/shuvi-app/entry/client/index.js +12 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.d.ts +0 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.js +2 -2
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.prod.d.ts +0 -0
- package/esm/shuvi-app/entry/client/run.prod.js +3 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/setup-env.d.ts +1 -1
- package/esm/shuvi-app/entry/client/setup-env.js +17 -0
- package/esm/shuvi-app/entry/server/index.d.ts +6 -0
- package/esm/shuvi-app/entry/server/index.js +7 -0
- package/esm/shuvi-app/react/AppComponent.d.ts +4 -0
- package/esm/shuvi-app/react/AppComponent.jsx +6 -0
- package/esm/shuvi-app/react/AppContainer.d.ts +6 -0
- package/esm/shuvi-app/react/AppContainer.jsx +23 -0
- package/esm/shuvi-app/react/Error.d.ts +5 -0
- package/esm/shuvi-app/react/Error.jsx +38 -0
- package/esm/shuvi-app/react/ErrorBoundary.d.ts +16 -0
- package/esm/shuvi-app/react/ErrorBoundary.jsx +25 -0
- package/esm/shuvi-app/react/ErrorPage.d.ts +5 -0
- package/esm/shuvi-app/react/ErrorPage.jsx +7 -0
- package/esm/shuvi-app/react/Link.d.ts +7 -0
- package/esm/shuvi-app/react/Link.jsx +115 -0
- package/esm/shuvi-app/react/applicationContext.d.ts +7 -0
- package/esm/shuvi-app/react/applicationContext.jsx +10 -0
- package/esm/shuvi-app/react/dynamic.d.ts +31 -0
- package/esm/shuvi-app/react/dynamic.jsx +62 -0
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -0
- package/esm/shuvi-app/react/getRoutes.js +31 -0
- package/esm/shuvi-app/react/head/head-manager-context.d.ts +2 -0
- package/esm/shuvi-app/react/head/head-manager-context.js +2 -0
- package/esm/shuvi-app/react/head/head-manager.d.ts +10 -0
- package/esm/shuvi-app/react/head/head-manager.js +93 -0
- package/esm/shuvi-app/react/head/head.d.ts +33 -0
- package/esm/shuvi-app/react/head/head.jsx +178 -0
- package/esm/shuvi-app/react/head/index.d.ts +4 -0
- package/esm/shuvi-app/react/head/index.js +4 -0
- package/esm/shuvi-app/react/head/side-effect.d.ts +30 -0
- package/esm/shuvi-app/react/head/side-effect.jsx +44 -0
- package/esm/shuvi-app/react/head/types.d.ts +15 -0
- package/esm/shuvi-app/react/head/types.js +1 -0
- package/esm/shuvi-app/react/index.d.ts +4 -0
- package/esm/shuvi-app/react/index.js +4 -0
- package/esm/shuvi-app/react/loadRouteComponent.d.ts +4 -0
- package/esm/shuvi-app/react/loadRouteComponent.jsx +9 -0
- package/esm/shuvi-app/react/loadable/index.d.ts +2 -0
- package/esm/shuvi-app/react/loadable/index.js +2 -0
- package/esm/shuvi-app/react/loadable/loadable-context.d.ts +4 -0
- package/esm/shuvi-app/react/loadable/loadable-context.js +3 -0
- package/esm/shuvi-app/react/loadable/loadable.d.ts +30 -0
- package/esm/shuvi-app/react/loadable/loadable.js +277 -0
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.d.ts +8 -0
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +11 -0
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +2 -0
- package/esm/shuvi-app/react/redox-react/runtime.js +16 -0
- package/esm/shuvi-app/react/shuvi-runtime-api.d.ts +5 -0
- package/esm/shuvi-app/react/shuvi-runtime-api.js +5 -0
- package/esm/shuvi-app/react/types.d.ts +14 -0
- package/esm/shuvi-app/react/types.js +1 -0
- package/esm/shuvi-app/react/useLoaderData.d.ts +2 -0
- package/esm/shuvi-app/react/useLoaderData.js +27 -0
- package/esm/shuvi-app/react/utils/getDisplayName.d.ts +2 -0
- package/esm/shuvi-app/react/utils/getDisplayName.js +3 -0
- package/esm/shuvi-app/react/utils/requestIdleCallback.d.ts +2 -0
- package/esm/shuvi-app/react/utils/requestIdleCallback.js +20 -0
- package/esm/shuvi-app/react/utils/useIntersection.d.ts +8 -0
- package/esm/shuvi-app/react/utils/useIntersection.jsx +91 -0
- package/esm/shuvi-app/react/view/ReactView.client.d.ts +5 -0
- package/esm/shuvi-app/react/view/ReactView.client.jsx +64 -0
- package/esm/shuvi-app/react/view/ReactView.server.d.ts +4 -0
- package/esm/shuvi-app/react/view/ReactView.server.jsx +109 -0
- package/esm/shuvi-app/react/view/clientView.d.ts +3 -0
- package/esm/shuvi-app/react/view/clientView.js +2 -0
- package/esm/shuvi-app/react/view/index.d.ts +2 -0
- package/esm/shuvi-app/react/view/index.js +7 -0
- package/esm/shuvi-app/react/view/render-action.d.ts +10 -0
- package/esm/shuvi-app/react/view/render-action.js +29 -0
- package/esm/shuvi-app/react/view/serverView.d.ts +3 -0
- package/esm/shuvi-app/react/view/serverView.js +2 -0
- package/esm/shuvi-app/react/view/transformRoutes.d.ts +2 -0
- package/esm/shuvi-app/react/view/transformRoutes.js +3 -0
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +4 -0
- package/esm/shuvi-app/shuvi-runtime-index.js +2 -0
- package/esm/shuvi-app/shuvi-runtime-server.d.ts +6 -0
- package/esm/shuvi-app/shuvi-runtime-server.js +1 -0
- package/lib/node/features/custom-server/index.d.ts +4 -0
- package/lib/node/features/custom-server/index.js +9 -0
- package/lib/node/features/custom-server/server.d.ts +2 -0
- package/lib/node/features/custom-server/server.js +28 -0
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +51 -0
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +237 -0
- package/lib/node/features/filesystem-routes/api/apiRoutes.d.ts +7 -0
- package/lib/node/features/filesystem-routes/api/apiRoutes.js +35 -0
- package/lib/node/features/filesystem-routes/api/index.d.ts +3 -0
- package/lib/node/features/filesystem-routes/api/index.js +7 -0
- package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -0
- package/lib/node/features/filesystem-routes/api/middleware.js +44 -0
- package/lib/node/features/filesystem-routes/hooks.d.ts +3 -0
- package/lib/node/features/filesystem-routes/hooks.js +6 -0
- package/lib/node/features/filesystem-routes/index.d.ts +20 -0
- package/lib/node/features/filesystem-routes/index.js +180 -0
- package/lib/node/features/filesystem-routes/middleware/index.d.ts +2 -0
- package/lib/node/features/filesystem-routes/middleware/index.js +7 -0
- package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -0
- package/lib/node/features/filesystem-routes/middleware/middleware.js +42 -0
- package/lib/node/features/filesystem-routes/middleware/routes.d.ts +9 -0
- package/lib/node/features/filesystem-routes/middleware/routes.js +34 -0
- package/lib/node/features/filesystem-routes/page/index.d.ts +2 -0
- package/lib/node/features/filesystem-routes/page/index.js +21 -0
- package/lib/node/features/filesystem-routes/page/routes.d.ts +8 -0
- package/lib/node/features/filesystem-routes/page/routes.js +83 -0
- package/lib/node/features/filesystem-routes/page/store.d.ts +3 -0
- package/lib/node/features/filesystem-routes/page/store.js +10 -0
- package/lib/node/features/html-render/index.d.ts +19 -0
- package/lib/node/features/html-render/index.js +28 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.js +13 -0
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -0
- package/lib/node/features/html-render/lib/getPageMiddleware.js +56 -0
- package/lib/node/features/html-render/lib/index.d.ts +4 -0
- package/lib/node/features/html-render/lib/index.js +23 -0
- package/lib/node/features/html-render/lib/pageLoader.d.ts +1 -0
- package/lib/node/features/html-render/lib/pageLoader.js +42 -0
- package/lib/node/features/html-render/lib/renderToHTML.d.ts +6 -0
- package/lib/node/features/html-render/lib/renderToHTML.js +81 -0
- package/lib/node/features/html-render/lib/renderer/base.d.ts +17 -0
- package/lib/node/features/html-render/lib/renderer/base.js +70 -0
- package/lib/node/features/html-render/lib/renderer/htmlTag.d.ts +4 -0
- package/lib/node/features/html-render/lib/renderer/htmlTag.js +70 -0
- package/lib/node/features/html-render/lib/renderer/index.d.ts +15 -0
- package/lib/node/features/html-render/lib/renderer/index.js +48 -0
- package/lib/node/features/html-render/lib/renderer/spa.d.ts +5 -0
- package/lib/node/features/html-render/lib/renderer/spa.js +26 -0
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +5 -0
- package/lib/node/features/html-render/lib/renderer/ssr.js +70 -0
- package/lib/node/features/html-render/lib/renderer/types.d.ts +20 -0
- package/lib/node/features/html-render/lib/renderer/types.js +2 -0
- package/lib/node/features/html-render/lib/viewTemplate.d.ts +5 -0
- package/lib/node/features/html-render/lib/viewTemplate.js +37 -0
- package/lib/node/features/html-render/server.d.ts +2 -0
- package/lib/node/features/html-render/server.js +9 -0
- package/lib/node/features/html-render/serverHooks.d.ts +10 -0
- package/lib/node/features/html-render/serverHooks.js +13 -0
- package/lib/node/features/html-render/shuvi-app.d.ts +6 -0
- package/lib/node/features/html-render/shuvi-app.js +2 -0
- package/lib/node/features/index.d.ts +32 -0
- package/lib/node/features/index.js +25 -0
- package/lib/node/features/main/buildHtml.d.ts +8 -0
- package/lib/node/features/main/buildHtml.js +64 -0
- package/lib/node/features/main/generateResource.d.ts +3 -0
- package/lib/node/features/main/generateResource.js +56 -0
- package/lib/node/features/main/index.d.ts +3 -0
- package/lib/node/features/main/index.js +82 -0
- package/lib/node/features/middlewares.d.ts +4 -0
- package/lib/node/features/middlewares.js +23 -0
- package/lib/node/features/model/index.d.ts +21 -0
- package/lib/node/features/model/index.js +54 -0
- package/lib/node/features/model/runtime.d.ts +13 -0
- package/lib/node/features/model/runtime.js +47 -0
- package/lib/node/features/model/server.d.ts +3 -0
- package/lib/node/features/model/server.js +12 -0
- package/lib/node/features/model/shuvi-app.d.ts +6 -0
- package/lib/node/features/model/shuvi-app.js +2 -0
- package/lib/node/features/on-demand-compile-page/emptyComponent.d.ts +1 -0
- package/lib/node/features/on-demand-compile-page/emptyComponent.js +7 -0
- package/lib/node/features/on-demand-compile-page/index.d.ts +15 -0
- package/lib/node/features/on-demand-compile-page/index.js +36 -0
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +11 -0
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +104 -0
- package/lib/node/index.d.ts +6 -0
- package/lib/node/index.js +38 -0
- package/lib/{paths.d.ts → node/paths.d.ts} +1 -2
- package/lib/node/paths.js +36 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +42 -0
- package/lib/node/shuvi-type-extensions-node.js +3 -0
- package/lib/node/targets/react/bundler/index.d.ts +16 -0
- package/lib/node/targets/react/bundler/index.js +102 -0
- package/lib/node/targets/react/index.d.ts +32 -0
- package/lib/node/targets/react/index.js +28 -0
- package/lib/node/targets/react/redox-react/index.d.ts +18 -0
- package/lib/node/targets/react/redox-react/index.js +50 -0
- package/lib/shared/appTypes.d.ts +15 -0
- package/lib/shared/appTypes.js +2 -0
- package/lib/shared/configTypes.d.ts +14 -0
- package/lib/shared/configTypes.js +2 -0
- package/lib/shared/index.d.ts +5 -0
- package/lib/shared/index.js +21 -0
- package/lib/shared/renderTypes.d.ts +44 -0
- package/lib/shared/renderTypes.js +2 -0
- package/lib/shared/routeTypes.d.ts +47 -0
- package/lib/shared/routeTypes.js +2 -0
- package/lib/shared/serverTypes.d.ts +6 -0
- package/lib/shared/serverTypes.js +2 -0
- package/package.json +78 -15
- package/shuvi-type-extensions-node.d.ts +2 -0
- package/shuvi-type-extensions-runtime.d.ts +36 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -44
- package/lib/paths.js +0 -7
- package/shuvi-app/application/client/create-application-factory.d.ts +0 -3
- package/shuvi-app/application/client/create-application-factory.js +0 -70
- package/shuvi-app/application/client/create-application-history-browser.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-browser.js +0 -3
- package/shuvi-app/application/client/create-application-history-hash.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-hash.js +0 -3
- package/shuvi-app/application/client/create-application-history-memory.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-memory.js +0 -3
- package/shuvi-app/application/server/create-application-spa.d.ts +0 -2
- package/shuvi-app/application/server/create-application-spa.js +0 -8
- package/shuvi-app/application/server/create-application.d.ts +0 -2
- package/shuvi-app/application/server/create-application.js +0 -25
- package/shuvi-app/entry/client/index.d.ts +0 -1
- package/shuvi-app/entry/client/index.js +0 -11
- package/shuvi-app/entry/client/run.prod.js +0 -3
- package/shuvi-app/entry/client/setup-app.d.ts +0 -3
- package/shuvi-app/entry/client/setup-app.js +0 -38
- package/shuvi-app/entry/client/setup-env.js +0 -27
- package/shuvi-app/entry/server/index.d.ts +0 -6
- package/shuvi-app/entry/server/index.js +0 -7
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const service_1 = require("@shuvi/service");
|
|
31
|
+
const paths_1 = require("../../paths");
|
|
32
|
+
const server_1 = __importDefault(require("./server"));
|
|
33
|
+
const resolveLib = (module) => path.dirname(require.resolve(path.join(module, 'package.json')));
|
|
34
|
+
const core = (0, service_1.createPlugin)({
|
|
35
|
+
addRuntimeService: () => [
|
|
36
|
+
{
|
|
37
|
+
source: resolveLib('@shuvi/redox'),
|
|
38
|
+
exported: '*',
|
|
39
|
+
filepath: 'model.ts'
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
configWebpack: config => {
|
|
43
|
+
config.resolve.alias.set('@shuvi/redox', resolveLib('@shuvi/redox'));
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
exports.default = {
|
|
48
|
+
core,
|
|
49
|
+
runtime: {
|
|
50
|
+
plugin: (0, paths_1.resolvePkgFile)('lib/node/features/model/runtime.js')
|
|
51
|
+
},
|
|
52
|
+
server: server_1.default,
|
|
53
|
+
types: (0, paths_1.resolvePkgFile)('lib/node/features/model/shuvi-app.d.ts')
|
|
54
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IStoreManager } from '@shuvi/redox';
|
|
2
|
+
import { IAppContext } from '@shuvi/platform-shared/shared';
|
|
3
|
+
export declare type InitRedox = (params: {
|
|
4
|
+
initialState: any;
|
|
5
|
+
ctx: IAppContext;
|
|
6
|
+
}) => IStoreManager;
|
|
7
|
+
declare module '@shuvi/runtime' {
|
|
8
|
+
interface CustomAppContext {
|
|
9
|
+
storeManager?: IStoreManager;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/runtime").CustomRuntimePluginHooks, void>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const redox_1 = require("@shuvi/redox");
|
|
4
|
+
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
5
|
+
let currentStoreManager;
|
|
6
|
+
const isServer = typeof window === 'undefined';
|
|
7
|
+
// for client, singleton mode
|
|
8
|
+
// for server, return new store
|
|
9
|
+
const initStore = ({ initialState, ctx }) => {
|
|
10
|
+
const createStoreInstance = () => {
|
|
11
|
+
// return createRedox(initialState, {
|
|
12
|
+
// ...ctx,
|
|
13
|
+
// isServer
|
|
14
|
+
// });
|
|
15
|
+
return (0, redox_1.redox)({
|
|
16
|
+
initialState
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
// for server
|
|
20
|
+
if (isServer) {
|
|
21
|
+
return createStoreInstance();
|
|
22
|
+
}
|
|
23
|
+
// for client is singleton, just init once
|
|
24
|
+
if (currentStoreManager) {
|
|
25
|
+
return currentStoreManager;
|
|
26
|
+
}
|
|
27
|
+
currentStoreManager = createStoreInstance();
|
|
28
|
+
return currentStoreManager;
|
|
29
|
+
};
|
|
30
|
+
exports.default = (0, shared_1.createRuntimePlugin)({
|
|
31
|
+
appContext: ctx => {
|
|
32
|
+
if (!ctx.storeManager) {
|
|
33
|
+
let initialState = {};
|
|
34
|
+
if (!isServer) {
|
|
35
|
+
initialState = (0, shared_1.getPageData)('redox');
|
|
36
|
+
}
|
|
37
|
+
if (ctx.pageData && ctx.pageData.redox) {
|
|
38
|
+
initialState = ctx.pageData.redox;
|
|
39
|
+
}
|
|
40
|
+
ctx.storeManager = initStore({
|
|
41
|
+
ctx,
|
|
42
|
+
initialState
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return ctx;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const service_1 = require("@shuvi/service");
|
|
4
|
+
exports.default = (0, service_1.createServerPlugin)({
|
|
5
|
+
getPageData: appContext => {
|
|
6
|
+
const { storeManager } = appContext;
|
|
7
|
+
delete appContext.storeManager;
|
|
8
|
+
return {
|
|
9
|
+
redox: storeManager === null || storeManager === void 0 ? void 0 : storeManager.getState()
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const _default: import("@shuvi/hook").IPluginInstance<{
|
|
2
|
+
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
3
|
+
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
4
|
+
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
5
|
+
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
+
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
7
|
+
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
8
|
+
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
9
|
+
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
10
|
+
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
11
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
12
|
+
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
13
|
+
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
14
|
+
export default _default;
|
|
15
|
+
export { default as OnDemandRouteManager } from './onDemandRouteManager';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OnDemandRouteManager = void 0;
|
|
7
|
+
const service_1 = require("@shuvi/service");
|
|
8
|
+
const escapeRegExp_1 = require("@shuvi/utils/lib/escapeRegExp");
|
|
9
|
+
const module_replace_plugin_1 = __importDefault(require("@shuvi/toolpack/lib/webpack/plugins/module-replace-plugin"));
|
|
10
|
+
const require_cache_hot_reloader_plugin_1 = __importDefault(require("@shuvi/toolpack/lib/webpack/plugins/require-cache-hot-reloader-plugin"));
|
|
11
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
12
|
+
const dumbRouteComponent = require.resolve('./emptyComponent');
|
|
13
|
+
exports.default = (0, service_1.createPlugin)({
|
|
14
|
+
configWebpack(config, _, ctx) {
|
|
15
|
+
if (ctx.mode === 'development') {
|
|
16
|
+
config.plugin('private/module-replace-plugin').use(module_replace_plugin_1.default, [
|
|
17
|
+
{
|
|
18
|
+
modules: [
|
|
19
|
+
{
|
|
20
|
+
resourceQuery: RegExp((0, escapeRegExp_1.escapeRegExp)(`?${constants_1.ROUTE_RESOURCE_QUERYSTRING}`)),
|
|
21
|
+
module: dumbRouteComponent
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]);
|
|
26
|
+
// Even though require.cache is server only we have to clear assets from both compilations
|
|
27
|
+
// This is because the client compilation generates the build manifest that's used on the server side
|
|
28
|
+
config
|
|
29
|
+
.plugin('private/require-cache-hot-reloader')
|
|
30
|
+
.use(require_cache_hot_reloader_plugin_1.default);
|
|
31
|
+
}
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
var onDemandRouteManager_1 = require("./onDemandRouteManager");
|
|
36
|
+
Object.defineProperty(exports, "OnDemandRouteManager", { enumerable: true, get: function () { return __importDefault(onDemandRouteManager_1).default; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRequestHandlerWithNext, IServerPluginContext } from '@shuvi/service';
|
|
2
|
+
import { DevMiddleware } from '@shuvi/service/lib/server/middlewares/dev';
|
|
3
|
+
export default class OnDemandRouteManager {
|
|
4
|
+
devMiddleware: DevMiddleware | null;
|
|
5
|
+
_serverPluginContext: IServerPluginContext;
|
|
6
|
+
constructor(serverPluginContext: IServerPluginContext);
|
|
7
|
+
getServerMiddleware(): IRequestHandlerWithNext;
|
|
8
|
+
ensureRoutesMiddleware(): IRequestHandlerWithNext;
|
|
9
|
+
ensureRoutes(pathname: string): Promise<void>;
|
|
10
|
+
private _activateModules;
|
|
11
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const router_1 = require("@shuvi/router");
|
|
16
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
17
|
+
const resources_1 = require("@shuvi/service/lib/resources");
|
|
18
|
+
const module_replace_plugin_1 = __importDefault(require("@shuvi/toolpack/lib/webpack/plugins/module-replace-plugin"));
|
|
19
|
+
const index_1 = require("../filesystem-routes/index");
|
|
20
|
+
function acceptsHtml(header, { htmlAcceptHeaders = ['text/html', '*/*'] } = {}) {
|
|
21
|
+
for (var i = 0; i < htmlAcceptHeaders.length; i++) {
|
|
22
|
+
if (header.indexOf(htmlAcceptHeaders[i]) !== -1) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
class OnDemandRouteManager {
|
|
29
|
+
constructor(serverPluginContext) {
|
|
30
|
+
this.devMiddleware = null;
|
|
31
|
+
this._serverPluginContext = serverPluginContext;
|
|
32
|
+
}
|
|
33
|
+
getServerMiddleware() {
|
|
34
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const pathname = req.pathname;
|
|
36
|
+
if (!pathname.startsWith(this._serverPluginContext.assetPublicPath)) {
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
if (!this.devMiddleware) {
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
const chunkName = pathname.replace(this._serverPluginContext.assetPublicPath, '');
|
|
43
|
+
const chunkInitiatorModule = resources_1.clientManifest.chunkRequest[chunkName];
|
|
44
|
+
if (!chunkInitiatorModule) {
|
|
45
|
+
return next();
|
|
46
|
+
}
|
|
47
|
+
const task = module_replace_plugin_1.default.restoreModule(chunkInitiatorModule);
|
|
48
|
+
if (task) {
|
|
49
|
+
yield this.devMiddleware.invalidate();
|
|
50
|
+
yield task;
|
|
51
|
+
}
|
|
52
|
+
next();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
ensureRoutesMiddleware() {
|
|
56
|
+
return (req, _res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const accept = req.headers['accept'];
|
|
58
|
+
if (req.method !== 'GET') {
|
|
59
|
+
return next();
|
|
60
|
+
}
|
|
61
|
+
else if (!accept) {
|
|
62
|
+
return next();
|
|
63
|
+
}
|
|
64
|
+
else if (accept.indexOf('application/json') === 0) {
|
|
65
|
+
return next();
|
|
66
|
+
}
|
|
67
|
+
else if (!acceptsHtml(accept, { htmlAcceptHeaders: ['text/html'] })) {
|
|
68
|
+
return next();
|
|
69
|
+
}
|
|
70
|
+
let err = null;
|
|
71
|
+
try {
|
|
72
|
+
yield this.ensureRoutes(req.pathname || '/');
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
err = error;
|
|
76
|
+
}
|
|
77
|
+
next(err);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
ensureRoutes(pathname) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const matchedRoutes = (0, router_1.matchRoutes)((0, index_1.getRoutes)(), pathname) || [];
|
|
83
|
+
const modulesToActivate = matchedRoutes
|
|
84
|
+
.map(({ route: { component } }) => component ? `${component}?${constants_1.ROUTE_RESOURCE_QUERYSTRING}` : '')
|
|
85
|
+
.filter(Boolean);
|
|
86
|
+
return this._activateModules(modulesToActivate);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
_activateModules(modules) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
if (!this.devMiddleware) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const tasks = modules
|
|
95
|
+
.map(m => module_replace_plugin_1.default.restoreModule(m))
|
|
96
|
+
.filter(Boolean);
|
|
97
|
+
if (tasks.length) {
|
|
98
|
+
this.devMiddleware.invalidate();
|
|
99
|
+
yield Promise.all(tasks);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.default = OnDemandRouteManager;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const node_1 = require("@shuvi/platform-shared/node");
|
|
13
|
+
const features_1 = require("./features");
|
|
14
|
+
const paths_1 = require("./paths");
|
|
15
|
+
const platform = ({ framework = 'react' } = {}) => (platformContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const mainPlugin = (0, features_1.getMainPlugin)(platformContext);
|
|
17
|
+
const platformFramework = require(`./targets/${framework}`).default;
|
|
18
|
+
const platformFrameworkContent = yield platformFramework();
|
|
19
|
+
const platformModule = platformFrameworkContent.platformModule;
|
|
20
|
+
const polyfills = platformFrameworkContent.polyfills;
|
|
21
|
+
const getPresetRuntimeFiles = (0, node_1.getPresetRuntimeFilesCreator)(platformModule, polyfills);
|
|
22
|
+
return {
|
|
23
|
+
types: [
|
|
24
|
+
(0, paths_1.resolvePkgFile)('shuvi-env.d.ts'),
|
|
25
|
+
(0, paths_1.resolvePkgFile)('shuvi-image.d.ts')
|
|
26
|
+
],
|
|
27
|
+
plugins: [
|
|
28
|
+
...node_1.SharedPlugins,
|
|
29
|
+
mainPlugin,
|
|
30
|
+
...features_1.featurePlugins,
|
|
31
|
+
...platformFrameworkContent.plugins
|
|
32
|
+
],
|
|
33
|
+
getPresetRuntimeFiles,
|
|
34
|
+
getMiddlewares: features_1.getMiddlewares,
|
|
35
|
+
getMiddlewaresBeforeDevMiddlewares: features_1.getMiddlewaresBeforeDevMiddlewares
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
exports.default = platform;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const PACKAGE_DIR: string;
|
|
2
|
-
export declare const resolveAppFile: (...paths: string[]) => string;
|
|
3
1
|
export declare const resolveDep: (module: string) => string;
|
|
4
2
|
export declare const resolveLib: (module: string) => string;
|
|
3
|
+
export declare const resolvePkgFile: (...paths: string[]) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.resolvePkgFile = exports.resolveLib = exports.resolveDep = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const PACKAGE_DIR = path.resolve(__dirname, '..', '..');
|
|
29
|
+
// export const resolveToModulePath = (...paths: string[]) =>
|
|
30
|
+
// `@shuvi/platform-web/${paths.join('/')}`;
|
|
31
|
+
const resolveDep = (module) => require.resolve(module);
|
|
32
|
+
exports.resolveDep = resolveDep;
|
|
33
|
+
const resolveLib = (module) => path.dirname((0, exports.resolveDep)(path.join(module, 'package.json')));
|
|
34
|
+
exports.resolveLib = resolveLib;
|
|
35
|
+
const resolvePkgFile = (...paths) => path.join(PACKAGE_DIR, ...paths);
|
|
36
|
+
exports.resolvePkgFile = resolvePkgFile;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import '@shuvi/platform-shared/shuvi-type-extensions-node';
|
|
2
|
+
import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
|
|
3
|
+
import { IMiddlewareRoutes, CreateAppServer, IApiRoutes, IServerModule, PlatformWebCustomConfig } from '../shared/index';
|
|
4
|
+
import { IViewServer } from './features/html-render/index';
|
|
5
|
+
import { addRoutes, addMiddlewareRoutes } from './features/filesystem-routes/hooks';
|
|
6
|
+
import { extendedHooks } from './features/html-render/serverHooks';
|
|
7
|
+
export {};
|
|
8
|
+
declare module '@shuvi/service/lib/resources' {
|
|
9
|
+
const server: {
|
|
10
|
+
server: IServerModule;
|
|
11
|
+
apiRoutes: IApiRoutes;
|
|
12
|
+
middlewareRoutes: IMiddlewareRoutes;
|
|
13
|
+
application: {
|
|
14
|
+
createApp: CreateAppServer;
|
|
15
|
+
};
|
|
16
|
+
view: IViewServer;
|
|
17
|
+
};
|
|
18
|
+
const documentPath: string;
|
|
19
|
+
const clientManifest: IManifest;
|
|
20
|
+
const serverManifest: IManifest;
|
|
21
|
+
}
|
|
22
|
+
declare global {
|
|
23
|
+
namespace ShuviService {
|
|
24
|
+
interface CustomConfig {
|
|
25
|
+
ssr: PlatformWebCustomConfig['ssr'];
|
|
26
|
+
router: PlatformWebCustomConfig['router'];
|
|
27
|
+
routes?: PlatformWebCustomConfig['routes'];
|
|
28
|
+
middlewareRoutes?: PlatformWebCustomConfig['middlewareRoutes'];
|
|
29
|
+
apiRoutes?: PlatformWebCustomConfig['apiRoutes'];
|
|
30
|
+
conventionRoutes: PlatformWebCustomConfig['conventionRoutes'];
|
|
31
|
+
}
|
|
32
|
+
interface CustomCorePluginHooks {
|
|
33
|
+
addRoutes: typeof addRoutes;
|
|
34
|
+
addMiddlewareRoutes: typeof addMiddlewareRoutes;
|
|
35
|
+
}
|
|
36
|
+
interface CustomServerPluginHooks {
|
|
37
|
+
getPageData: typeof extendedHooks.getPageData;
|
|
38
|
+
handlePageRequest: typeof extendedHooks.handlePageRequest;
|
|
39
|
+
modifyHtml: typeof extendedHooks.modifyHtml;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
core: import("@shuvi/hook").IPluginInstance<{
|
|
3
|
+
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
4
|
+
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
5
|
+
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
+
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
+
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
8
|
+
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
9
|
+
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
10
|
+
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
11
|
+
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
12
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
13
|
+
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
14
|
+
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const service_1 = require("@shuvi/service");
|
|
31
|
+
const ReactRefreshWebpackPlugin_1 = __importDefault(require("@next/react-refresh-utils/ReactRefreshWebpackPlugin"));
|
|
32
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
33
|
+
const webpack_1 = require("webpack");
|
|
34
|
+
const configWebpack = (config, { name, webpack }, context) => {
|
|
35
|
+
const resolveLocal = (m, sub) => {
|
|
36
|
+
const pck = path.dirname(require.resolve(`${m}/package.json`));
|
|
37
|
+
return sub ? `${pck}/${sub}` : pck;
|
|
38
|
+
};
|
|
39
|
+
const resolveUser = (m) => path.join(context.paths.rootDir, 'node_modules', m);
|
|
40
|
+
const isReactVersionAfter18 = () => {
|
|
41
|
+
let version = '';
|
|
42
|
+
try {
|
|
43
|
+
version = require(resolveUser('react-dom')).version;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
version = require(resolveLocal('react-dom')).version;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
}
|
|
50
|
+
const majorVersion = parseInt(version.split('.')[0] || '', 10);
|
|
51
|
+
return majorVersion >= 18;
|
|
52
|
+
};
|
|
53
|
+
config.resolve.alias.set('@shuvi/service', resolveLocal('@shuvi/service'));
|
|
54
|
+
config.resolve.alias.set('@shuvi/router$', resolveLocal('@shuvi/router'));
|
|
55
|
+
config.resolve.alias.set('@shuvi/router-react$', resolveLocal('@shuvi/router-react'));
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
config.resolve.alias.set('react$', [
|
|
58
|
+
resolveUser('react'),
|
|
59
|
+
resolveLocal('react')
|
|
60
|
+
]);
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
config.resolve.alias.set('react/jsx-runtime$', [
|
|
63
|
+
resolveUser('react/jsx-runtime'),
|
|
64
|
+
resolveLocal('react', 'jsx-runtime')
|
|
65
|
+
]);
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
config.resolve.alias.set('react-dom$', [
|
|
68
|
+
resolveUser('react-dom'),
|
|
69
|
+
resolveLocal('react-dom')
|
|
70
|
+
]);
|
|
71
|
+
if (name === constants_1.BUNDLER_DEFAULT_TARGET && context.mode === 'development') {
|
|
72
|
+
config.module
|
|
73
|
+
.rule('main')
|
|
74
|
+
.oneOf('js')
|
|
75
|
+
.use('react-refresh-loader')
|
|
76
|
+
.loader(require.resolve('@next/react-refresh-utils/loader'))
|
|
77
|
+
.before('shuvi-swc-loader');
|
|
78
|
+
config
|
|
79
|
+
.plugin('react-refresh-plugin')
|
|
80
|
+
.use(ReactRefreshWebpackPlugin_1.default, [webpack]);
|
|
81
|
+
config.plugin('version-env-plugin').use(webpack_1.DefinePlugin, [
|
|
82
|
+
{
|
|
83
|
+
'process.env.__SHUVI__AFTER__REACT__18__': JSON.stringify(isReactVersionAfter18())
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
};
|
|
89
|
+
exports.default = {
|
|
90
|
+
core: (0, service_1.createPlugin)({
|
|
91
|
+
configWebpack,
|
|
92
|
+
addEntryCode(context) {
|
|
93
|
+
if (context.mode === 'development') {
|
|
94
|
+
const fastRefreshRuntime = require.resolve(`@next/react-refresh-utils/runtime`);
|
|
95
|
+
return `import "${fastRefreshRuntime}"`;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return '';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare const platformWebReact: () => {
|
|
2
|
+
plugins: (import("@shuvi/hook").IPluginInstance<{
|
|
3
|
+
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
4
|
+
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
5
|
+
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
+
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
+
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
8
|
+
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
9
|
+
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
10
|
+
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
11
|
+
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
12
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
13
|
+
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
14
|
+
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext> | {
|
|
15
|
+
core: import("@shuvi/hook").IPluginInstance<{
|
|
16
|
+
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
17
|
+
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
18
|
+
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
19
|
+
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
20
|
+
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
21
|
+
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
22
|
+
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
23
|
+
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
24
|
+
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
25
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
26
|
+
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
27
|
+
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
28
|
+
})[];
|
|
29
|
+
platformModule: string;
|
|
30
|
+
polyfills: string[];
|
|
31
|
+
};
|
|
32
|
+
export default platformWebReact;
|