catalyst-core 0.0.1-beta.2 → 0.0.1-beta.4
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/.eslintignore +9 -0
- package/.eslintrc +92 -0
- package/README.md +58 -43
- package/babel.config.json +1 -5
- package/bin/catalyst.js +35 -35
- package/changelog.md +26 -0
- package/config.json +1 -2
- package/{LICENSE → license} +2 -1
- package/{logger/index.js → logger.js} +13 -10
- package/package.json +87 -85
- package/router/ClientRouter.js +10 -6
- package/router/ServerRouter.js +2 -11
- package/scripts/build.js +26 -11
- package/scripts/checkVersion.js +5 -0
- package/scripts/devBuild.js +42 -0
- package/scripts/devServe.js +43 -0
- package/scripts/loadEnvironmentVariables.js +8 -21
- package/scripts/loadScriptsBeforeServerStarts.js +13 -21
- package/scripts/serve.js +27 -11
- package/scripts/start.js +19 -12
- package/scripts/validator.js +39 -11
- package/server/expressServer.js +50 -0
- package/server/renderer/document/Body.js +17 -18
- package/server/renderer/document/Head.js +7 -8
- package/server/renderer/document/index.js +2 -0
- package/server/renderer/extract.js +25 -24
- package/server/renderer/handler.js +220 -208
- package/server/renderer/index.js +6 -7
- package/server/renderer/render.js +32 -19
- package/server/startServer.js +66 -0
- package/server/utils/metaTags.js +13 -0
- package/server/utils/userAgentUtil.js +51 -0
- package/server/utils/validator.js +39 -10
- package/webpack/babel-plugins/remove-client.plugin.js +1 -1
- package/webpack/babel-plugins/remove-ssr.plugin.js +1 -1
- package/webpack/babel.config.client.js +3 -3
- package/webpack/babel.config.ssr.js +1 -1
- package/webpack/base.babel.js +37 -36
- package/webpack/development.client.babel.js +11 -8
- package/webpack/production.client.babel.js +1 -2
- package/webpack/production.ssr.babel.js +3 -3
- package/webpack/scssParams.js +35 -15
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/checkVersion.js +0 -3
- package/config/config.js +0 -24
- package/packages/create-framework-app/node_modules/.package-lock.json +0 -249
- package/packages/create-framework-app/templates/redux-js/node_modules/@babel/core/lib/config/caching.js +0 -261
- package/packages/create-framework-app/templates/redux-js/node_modules/@remix-run/router/dist/router.js +0 -4327
- package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/router.js +0 -15
- package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +0 -46
- package/reducer/index.js +0 -88
- package/reducer/loadableConfigReducer.js +0 -19
- package/store/index.dev.js +0 -73
- package/store/index.js +0 -25
- package/store/index.prod.js +0 -66
- package/types/caching.d.ts +0 -1
- package/types/config/config.d.ts +0 -19
- package/types/index.d.ts +0 -1
- package/types/logger/index.d.ts +0 -14
- package/types/reducer/index.d.ts +0 -22
- package/types/reducer/loadableConfigReducer.d.ts +0 -9
- package/types/router/ClientRouter.d.ts +0 -5
- package/types/router/ServerRouter.d.ts +0 -7
- package/types/router/index.d.ts +0 -8
- package/types/router.d.ts +0 -1
- package/types/scripts/build.d.ts +0 -1
- package/types/scripts/loadEnvironmentVariables.d.ts +0 -5
- package/types/scripts/loadScriptsBeforeServerStarts.d.ts +0 -1
- package/types/scripts/prepare.d.ts +0 -1
- package/types/scripts/registerAliases.d.ts +0 -1
- package/types/scripts/serve.d.ts +0 -1
- package/types/scripts/start.d.ts +0 -1
- package/types/scripts/validator.d.ts +0 -9
- package/types/scripts/verifyConfig.d.ts +0 -1
- package/types/server/mainIndex.d.ts +0 -1
- package/types/server/mainServer.d.ts +0 -2
- package/types/server/renderer/document/Body.d.ts +0 -11
- package/types/server/renderer/document/Head.d.ts +0 -11
- package/types/server/renderer/document/index.d.ts +0 -2
- package/types/server/renderer/extract.d.ts +0 -18
- package/types/server/renderer/handler.d.ts +0 -6
- package/types/server/renderer/index.d.ts +0 -2
- package/types/server/renderer/render.d.ts +0 -38
- package/types/server/renderer/userAgentUtil.d.ts +0 -1
- package/types/store/index.d.ts +0 -11
- package/types/store/index.dev.d.ts +0 -8
- package/types/store/index.prod.d.ts +0 -8
- package/types/webpack/babel-plugins/remove-client.plugin.d.ts +0 -10
- package/types/webpack/babel-plugins/remove-ssr.plugin.d.ts +0 -10
- package/types/webpack/babel.config.client.d.ts +0 -21
- package/types/webpack/babel.config.d.ts +0 -16
- package/types/webpack/babel.config.ssr.d.ts +0 -21
- package/types/webpack/base.babel.d.ts +0 -184
- package/types/webpack/development.client.babel.d.ts +0 -1
- package/types/webpack/plugins/mime-types.d.ts +0 -78
- package/types/webpack/plugins/route-manifest-plugin.d.ts +0 -1
- package/types/webpack/plugins/upload-assets-plugin.d.ts +0 -1
- package/types/webpack/production.client.babel.d.ts +0 -174
- package/types/webpack/production.ssr.babel.d.ts +0 -2
- package/types/webpack/scssParams.d.ts +0 -2
package/scripts/validator.js
CHANGED
|
@@ -7,7 +7,7 @@ const handleError = e => {
|
|
|
7
7
|
const validatePreInitServer = fn => {
|
|
8
8
|
try {
|
|
9
9
|
if (!fn) throw new Error("preServerInit named function should be defined in server/index.js");
|
|
10
|
-
if (typeof fn !==
|
|
10
|
+
if (typeof fn !== "function") throw new Error("preServerInit should be function present in server/index.js");
|
|
11
11
|
return true;
|
|
12
12
|
} catch (e) {
|
|
13
13
|
handleError(e);
|
|
@@ -16,7 +16,7 @@ const validatePreInitServer = fn => {
|
|
|
16
16
|
const validateMiddleware = fn => {
|
|
17
17
|
try {
|
|
18
18
|
if (!fn) throw new Error("addMiddlewares named function not found in server/server.js");
|
|
19
|
-
if (typeof fn !==
|
|
19
|
+
if (typeof fn !== "function") throw new Error("addMiddlewares should be function present in server/server.js");
|
|
20
20
|
return true;
|
|
21
21
|
} catch (e) {
|
|
22
22
|
handleError(e);
|
|
@@ -25,7 +25,7 @@ const validateMiddleware = fn => {
|
|
|
25
25
|
const validateReducerFunction = fn => {
|
|
26
26
|
try {
|
|
27
27
|
if (!fn) throw new Error("reducer not found in src/js/containers/App/reducer");
|
|
28
|
-
if (typeof fn !==
|
|
28
|
+
if (typeof fn !== "function") throw new Error("reducer should present in src/js/containers/App/reducer");
|
|
29
29
|
return true;
|
|
30
30
|
} catch (e) {
|
|
31
31
|
handleError(e);
|
|
@@ -34,7 +34,23 @@ const validateReducerFunction = fn => {
|
|
|
34
34
|
const validateConfigFile = obj => {
|
|
35
35
|
try {
|
|
36
36
|
if (!obj) throw new Error("config not found in config folder");
|
|
37
|
-
if (typeof obj !==
|
|
37
|
+
if (typeof obj !== "object") throw new Error("config object should be exported from config folder inside your project root directory");
|
|
38
|
+
if (typeof obj === "object") {
|
|
39
|
+
const requiredConfigKeys = {
|
|
40
|
+
NODE_SERVER_HOSTNAME: "",
|
|
41
|
+
NODE_SERVER_PORT: "",
|
|
42
|
+
WEBPACK_DEV_SERVER_HOSTNAME: "",
|
|
43
|
+
WEBPACK_DEV_SERVER_PORT: "",
|
|
44
|
+
BUILD_OUTPUT_PATH: "",
|
|
45
|
+
PUBLIC_STATIC_ASSET_PATH: "",
|
|
46
|
+
PUBLIC_STATIC_ASSET_URL: "",
|
|
47
|
+
CLIENT_ENV_VARIABLES: [],
|
|
48
|
+
ANALYZE_BUNDLE: ""
|
|
49
|
+
};
|
|
50
|
+
for (let key in requiredConfigKeys) {
|
|
51
|
+
if (!(key in obj)) throw new Error(`${key} key not found inside config.json`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
38
54
|
return true;
|
|
39
55
|
} catch (e) {
|
|
40
56
|
handleError(e);
|
|
@@ -43,7 +59,7 @@ const validateConfigFile = obj => {
|
|
|
43
59
|
const validatePackageJson = obj => {
|
|
44
60
|
try {
|
|
45
61
|
if (!obj) throw new Error("package.json not found in the project");
|
|
46
|
-
if (typeof obj !==
|
|
62
|
+
if (typeof obj !== "object") throw new Error("package.json should be defined in project root directory");
|
|
47
63
|
return true;
|
|
48
64
|
} catch (e) {
|
|
49
65
|
handleError(e);
|
|
@@ -52,7 +68,20 @@ const validatePackageJson = obj => {
|
|
|
52
68
|
const validateModuleAlias = obj => {
|
|
53
69
|
try {
|
|
54
70
|
if (!obj) throw new Error("moduleAliases not found in package.json file present in root directory.");
|
|
55
|
-
if (typeof obj !==
|
|
71
|
+
if (typeof obj !== "object") throw new Error("moduleAliases named object should be exported from package.json");
|
|
72
|
+
if (typeof obj === "object") {
|
|
73
|
+
const requiredModuleAliases = {
|
|
74
|
+
"@api": "api.js",
|
|
75
|
+
"@containers": "src/js/containers",
|
|
76
|
+
"@server": "server",
|
|
77
|
+
"@config": "config",
|
|
78
|
+
"@css": "src/static/css",
|
|
79
|
+
"@routes": "src/js/routes/"
|
|
80
|
+
};
|
|
81
|
+
for (let key in requiredModuleAliases) {
|
|
82
|
+
if (!(key in obj)) throw new Error(`${key} module alias not defined inside package.json`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
56
85
|
return true;
|
|
57
86
|
} catch (e) {
|
|
58
87
|
handleError(e);
|
|
@@ -61,7 +90,7 @@ const validateModuleAlias = obj => {
|
|
|
61
90
|
const validateConfigureStore = fn => {
|
|
62
91
|
try {
|
|
63
92
|
if (!fn) throw new Error("configureStore not found in file src/js/store/index.js");
|
|
64
|
-
if (typeof fn !==
|
|
93
|
+
if (typeof fn !== "function") throw new Error("configureStore should be function exported from src/js/store/index.js");
|
|
65
94
|
return true;
|
|
66
95
|
} catch (e) {
|
|
67
96
|
handleError(e);
|
|
@@ -69,8 +98,8 @@ const validateConfigureStore = fn => {
|
|
|
69
98
|
};
|
|
70
99
|
const validateGetRoutes = fn => {
|
|
71
100
|
try {
|
|
72
|
-
if (!fn) throw new Error("getRoutes not found in file src/js/
|
|
73
|
-
if (typeof fn !==
|
|
101
|
+
if (!fn) throw new Error("getRoutes not found in file src/js/routes/utils.js");
|
|
102
|
+
if (typeof fn !== "function") throw new Error("getRoutes should be function exported from src/js/routers/index.js");
|
|
74
103
|
return true;
|
|
75
104
|
} catch (e) {
|
|
76
105
|
handleError(e);
|
|
@@ -79,7 +108,7 @@ const validateGetRoutes = fn => {
|
|
|
79
108
|
const validateCustomDocument = fn => {
|
|
80
109
|
try {
|
|
81
110
|
if (!fn) throw new Error("document not found in file server/document.js");
|
|
82
|
-
if (typeof fn !==
|
|
111
|
+
if (typeof fn !== "function") throw new Error("document should be a react component exported from server/document.js");
|
|
83
112
|
return true;
|
|
84
113
|
} catch (e) {
|
|
85
114
|
handleError(e);
|
|
@@ -90,7 +119,6 @@ module.exports = {
|
|
|
90
119
|
validateConfigureStore,
|
|
91
120
|
validateCustomDocument,
|
|
92
121
|
validateGetRoutes,
|
|
93
|
-
validateModuleAlias,
|
|
94
122
|
validatePackageJson,
|
|
95
123
|
validateReducerFunction,
|
|
96
124
|
validateModuleAlias,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _express = _interopRequireDefault(require("express"));
|
|
9
|
+
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
10
|
+
var _compression = _interopRequireDefault(require("compression"));
|
|
11
|
+
var _cookieParser = _interopRequireDefault(require("cookie-parser"));
|
|
12
|
+
var _expressStaticGzip = _interopRequireDefault(require("express-static-gzip"));
|
|
13
|
+
var _renderer = _interopRequireDefault(require("./renderer"));
|
|
14
|
+
var _server = require("@server/server.js");
|
|
15
|
+
var _validator = require("./utils/validator");
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
const env = process.env.NODE_ENV || "development";
|
|
18
|
+
const app = (0, _express.default)();
|
|
19
|
+
|
|
20
|
+
// This middleware is being used to extract the body of the request
|
|
21
|
+
app.use(_bodyParser.default.json());
|
|
22
|
+
|
|
23
|
+
// This middleware has been added to accommodate “byetstream array”
|
|
24
|
+
app.use(_bodyParser.default.raw({
|
|
25
|
+
type: "application/*"
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
// This middleware is being used to parse cookies!
|
|
29
|
+
app.use((0, _cookieParser.default)());
|
|
30
|
+
|
|
31
|
+
// All the middlewares defined by the user will run here.
|
|
32
|
+
if ((0, _validator.validateMiddleware)(_server.addMiddlewares)) (0, _server.addMiddlewares)(app);
|
|
33
|
+
|
|
34
|
+
// The middleware will attempt to compress response bodies for all request that traverse through the middleware
|
|
35
|
+
app.use((0, _compression.default)());
|
|
36
|
+
|
|
37
|
+
// This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
|
|
38
|
+
// expressStaticGzip will compress the assets.
|
|
39
|
+
if (env === "production") {
|
|
40
|
+
app.use(process.env.PUBLIC_STATIC_ASSET_PATH, (0, _expressStaticGzip.default)(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`), {
|
|
41
|
+
enableBrotli: true,
|
|
42
|
+
orderPreference: ["br", "gzip", "deflate"]
|
|
43
|
+
}));
|
|
44
|
+
} else {
|
|
45
|
+
app.use(process.env.PUBLIC_STATIC_ASSET_PATH, _express.default.static(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// This middleware handles document requests.
|
|
49
|
+
app.use("*", _renderer.default);
|
|
50
|
+
var _default = exports.default = app;
|
|
@@ -4,33 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Body = Body;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _react2 = _interopRequireDefault(_react);
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
/**
|
|
11
10
|
* Body component which will be used in page component
|
|
12
|
-
* @param {object} initialState - redux store
|
|
13
|
-
* @param {object}
|
|
14
|
-
* @param {object}
|
|
15
|
-
* @param {object}
|
|
16
|
-
* @param {object}
|
|
17
|
-
* @param {object} fetcherData -
|
|
11
|
+
* @param {object} initialState - initial state object for redux store
|
|
12
|
+
* @param {object} firstFoldCss - style elements extracted for initial page load
|
|
13
|
+
* @param {object} firstFoldJS - javascript elements extracted for initial page load
|
|
14
|
+
* @param {object} jsx - page jsx code
|
|
15
|
+
* @param {object} statusCode - document request status code
|
|
16
|
+
* @param {object} fetcherData - contains data from executing serverFetcher function
|
|
18
17
|
*/
|
|
19
18
|
function Body(props) {
|
|
20
19
|
const {
|
|
21
|
-
initialState,
|
|
22
|
-
statusCode,
|
|
23
|
-
firstFoldCss,
|
|
24
|
-
firstFoldJS,
|
|
25
|
-
jsx,
|
|
26
|
-
fetcherData
|
|
20
|
+
initialState = {},
|
|
21
|
+
statusCode = "",
|
|
22
|
+
firstFoldCss = "",
|
|
23
|
+
firstFoldJS = "",
|
|
24
|
+
jsx = "",
|
|
25
|
+
fetcherData = {}
|
|
27
26
|
} = props;
|
|
28
|
-
return /*#__PURE__*/
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("body", null, firstFoldCss, firstFoldJS, jsx, /*#__PURE__*/_react.default.createElement("script", {
|
|
29
28
|
dangerouslySetInnerHTML: {
|
|
30
29
|
__html: `
|
|
31
|
-
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
|
|
32
|
-
window.__STATUS_CODE__ = ${statusCode}
|
|
33
|
-
window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
|
|
30
|
+
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
|
|
31
|
+
window.__STATUS_CODE__ = ${statusCode}
|
|
32
|
+
window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
|
|
34
33
|
`
|
|
35
34
|
}
|
|
36
35
|
}), props.children);
|
|
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Head = Head;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _react2 = _interopRequireDefault(_react);
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
/**
|
|
11
10
|
* Head component which will be used in page rendering
|
|
@@ -20,23 +19,23 @@ function Head(props) {
|
|
|
20
19
|
const {
|
|
21
20
|
pageCss,
|
|
22
21
|
pageJS,
|
|
23
|
-
|
|
22
|
+
metaTags,
|
|
24
23
|
isBot,
|
|
25
24
|
publicAssetPath,
|
|
26
25
|
fetcherData
|
|
27
26
|
} = props;
|
|
28
|
-
return /*#__PURE__*/
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("head", null, /*#__PURE__*/_react.default.createElement("meta", {
|
|
29
28
|
charSet: "utf-8"
|
|
30
|
-
}), /*#__PURE__*/
|
|
29
|
+
}), /*#__PURE__*/_react.default.createElement("meta", {
|
|
31
30
|
name: "viewport",
|
|
32
31
|
content: "width=device-width, initial-scale=1"
|
|
33
|
-
}), publicAssetPath && /*#__PURE__*/
|
|
32
|
+
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
34
33
|
rel: "preconnect",
|
|
35
34
|
href: publicAssetPath
|
|
36
|
-
}), publicAssetPath && /*#__PURE__*/
|
|
35
|
+
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
37
36
|
rel: "dns-prefetch",
|
|
38
37
|
href: publicAssetPath
|
|
39
|
-
}),
|
|
38
|
+
}), metaTags && metaTags, !isBot && pageJS, !isBot && /*#__PURE__*/_react.default.createElement("style", {
|
|
40
39
|
dangerouslySetInnerHTML: {
|
|
41
40
|
__html: pageCss
|
|
42
41
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var _Head = require("./Head");
|
|
7
7
|
Object.keys(_Head).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _Head[key]) return;
|
|
9
10
|
Object.defineProperty(exports, key, {
|
|
10
11
|
enumerable: true,
|
|
11
12
|
get: function () {
|
|
@@ -16,6 +17,7 @@ Object.keys(_Head).forEach(function (key) {
|
|
|
16
17
|
var _Body = require("./Body");
|
|
17
18
|
Object.keys(_Body).forEach(function (key) {
|
|
18
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _Body[key]) return;
|
|
19
21
|
Object.defineProperty(exports, key, {
|
|
20
22
|
enumerable: true,
|
|
21
23
|
get: function () {
|
|
@@ -5,24 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.cacheCSS = cacheCSS;
|
|
7
7
|
exports.cacheJS = cacheJS;
|
|
8
|
-
exports.default =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const cachedCss = fetchCachedCSS(requestPath);
|
|
12
|
-
const cachedJS = fetchCachedJS(requestPath);
|
|
13
|
-
if (cachedCss || cachedJS) {
|
|
14
|
-
res.locals.pageJS = cachedJS;
|
|
15
|
-
res.locals.pageCss = cachedCss;
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.log("Error while reading lodable stats:");
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var _path = require("path");
|
|
23
|
-
var _path2 = _interopRequireDefault(_path);
|
|
24
|
-
var _fs = require("fs");
|
|
25
|
-
var _fs2 = _interopRequireDefault(_fs);
|
|
8
|
+
exports.default = _default;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
26
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
12
|
/**
|
|
28
13
|
* Stores css chunks styles into cache in string format
|
|
@@ -39,11 +24,13 @@ function cacheCSS(key, data) {
|
|
|
39
24
|
data.map(assetChunk => {
|
|
40
25
|
const assetPathArr = assetChunk.key.split("/");
|
|
41
26
|
const assetName = assetPathArr[assetPathArr.length - 1];
|
|
42
|
-
const ext =
|
|
43
|
-
if (ext === ".css") pageCss +=
|
|
27
|
+
const ext = _path.default.extname(assetName);
|
|
28
|
+
if (ext === ".css") pageCss += _fs.default.readFileSync(_path.default.resolve(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`, assetName));
|
|
44
29
|
});
|
|
45
30
|
} catch (error) {
|
|
46
|
-
|
|
31
|
+
if (process.env.NODE_ENV == "development") {
|
|
32
|
+
console.log("Error While Extracting The Chunk: ", _path.default.resolve(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`, assetName));
|
|
33
|
+
}
|
|
47
34
|
}
|
|
48
35
|
}
|
|
49
36
|
process.cssCache[key] = pageCss;
|
|
@@ -64,7 +51,7 @@ function cacheJS(key, data) {
|
|
|
64
51
|
/**
|
|
65
52
|
* returns cached css
|
|
66
53
|
* @param {string} key - router path
|
|
67
|
-
* @return {string} - cached css
|
|
54
|
+
* @return {string} - cached css
|
|
68
55
|
*/
|
|
69
56
|
function fetchCachedCSS(key) {
|
|
70
57
|
return process.cssCache && process.cssCache[key] ? process.cssCache[key] : null;
|
|
@@ -73,7 +60,7 @@ function fetchCachedCSS(key) {
|
|
|
73
60
|
/**
|
|
74
61
|
* returns cached js
|
|
75
62
|
* @param {string} key - router path
|
|
76
|
-
* @return {string} - cached js
|
|
63
|
+
* @return {string} - cached js
|
|
77
64
|
*/
|
|
78
65
|
function fetchCachedJS(key) {
|
|
79
66
|
return process.jsCache && process.jsCache[key] ? process.jsCache[key] : null;
|
|
@@ -83,4 +70,18 @@ function fetchCachedJS(key) {
|
|
|
83
70
|
* stores css and js in cache
|
|
84
71
|
* @param {object} res - response object
|
|
85
72
|
* @param {string} route - route path
|
|
86
|
-
*/
|
|
73
|
+
*/
|
|
74
|
+
function _default(res, route) {
|
|
75
|
+
try {
|
|
76
|
+
const requestPath = route.path;
|
|
77
|
+
const cachedCss = fetchCachedCSS(requestPath);
|
|
78
|
+
const cachedJS = fetchCachedJS(requestPath);
|
|
79
|
+
if (cachedCss || cachedJS) {
|
|
80
|
+
res.locals.pageJS = cachedJS;
|
|
81
|
+
res.locals.pageCss = cachedCss;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.log("Error while caching your assets.");
|
|
86
|
+
}
|
|
87
|
+
}
|