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.
Files changed (101) hide show
  1. package/.eslintignore +9 -0
  2. package/.eslintrc +92 -0
  3. package/README.md +58 -43
  4. package/babel.config.json +1 -5
  5. package/bin/catalyst.js +35 -35
  6. package/changelog.md +26 -0
  7. package/config.json +1 -2
  8. package/{LICENSE → license} +2 -1
  9. package/{logger/index.js → logger.js} +13 -10
  10. package/package.json +87 -85
  11. package/router/ClientRouter.js +10 -6
  12. package/router/ServerRouter.js +2 -11
  13. package/scripts/build.js +26 -11
  14. package/scripts/checkVersion.js +5 -0
  15. package/scripts/devBuild.js +42 -0
  16. package/scripts/devServe.js +43 -0
  17. package/scripts/loadEnvironmentVariables.js +8 -21
  18. package/scripts/loadScriptsBeforeServerStarts.js +13 -21
  19. package/scripts/serve.js +27 -11
  20. package/scripts/start.js +19 -12
  21. package/scripts/validator.js +39 -11
  22. package/server/expressServer.js +50 -0
  23. package/server/renderer/document/Body.js +17 -18
  24. package/server/renderer/document/Head.js +7 -8
  25. package/server/renderer/document/index.js +2 -0
  26. package/server/renderer/extract.js +25 -24
  27. package/server/renderer/handler.js +220 -208
  28. package/server/renderer/index.js +6 -7
  29. package/server/renderer/render.js +32 -19
  30. package/server/startServer.js +66 -0
  31. package/server/utils/metaTags.js +13 -0
  32. package/server/utils/userAgentUtil.js +51 -0
  33. package/server/utils/validator.js +39 -10
  34. package/webpack/babel-plugins/remove-client.plugin.js +1 -1
  35. package/webpack/babel-plugins/remove-ssr.plugin.js +1 -1
  36. package/webpack/babel.config.client.js +3 -3
  37. package/webpack/babel.config.ssr.js +1 -1
  38. package/webpack/base.babel.js +37 -36
  39. package/webpack/development.client.babel.js +11 -8
  40. package/webpack/production.client.babel.js +1 -2
  41. package/webpack/production.ssr.babel.js +3 -3
  42. package/webpack/scssParams.js +35 -15
  43. package/.prettierignore +0 -2
  44. package/.prettierrc.json +0 -7
  45. package/checkVersion.js +0 -3
  46. package/config/config.js +0 -24
  47. package/packages/create-framework-app/node_modules/.package-lock.json +0 -249
  48. package/packages/create-framework-app/templates/redux-js/node_modules/@babel/core/lib/config/caching.js +0 -261
  49. package/packages/create-framework-app/templates/redux-js/node_modules/@remix-run/router/dist/router.js +0 -4327
  50. package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/router.js +0 -15
  51. package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +0 -46
  52. package/reducer/index.js +0 -88
  53. package/reducer/loadableConfigReducer.js +0 -19
  54. package/store/index.dev.js +0 -73
  55. package/store/index.js +0 -25
  56. package/store/index.prod.js +0 -66
  57. package/types/caching.d.ts +0 -1
  58. package/types/config/config.d.ts +0 -19
  59. package/types/index.d.ts +0 -1
  60. package/types/logger/index.d.ts +0 -14
  61. package/types/reducer/index.d.ts +0 -22
  62. package/types/reducer/loadableConfigReducer.d.ts +0 -9
  63. package/types/router/ClientRouter.d.ts +0 -5
  64. package/types/router/ServerRouter.d.ts +0 -7
  65. package/types/router/index.d.ts +0 -8
  66. package/types/router.d.ts +0 -1
  67. package/types/scripts/build.d.ts +0 -1
  68. package/types/scripts/loadEnvironmentVariables.d.ts +0 -5
  69. package/types/scripts/loadScriptsBeforeServerStarts.d.ts +0 -1
  70. package/types/scripts/prepare.d.ts +0 -1
  71. package/types/scripts/registerAliases.d.ts +0 -1
  72. package/types/scripts/serve.d.ts +0 -1
  73. package/types/scripts/start.d.ts +0 -1
  74. package/types/scripts/validator.d.ts +0 -9
  75. package/types/scripts/verifyConfig.d.ts +0 -1
  76. package/types/server/mainIndex.d.ts +0 -1
  77. package/types/server/mainServer.d.ts +0 -2
  78. package/types/server/renderer/document/Body.d.ts +0 -11
  79. package/types/server/renderer/document/Head.d.ts +0 -11
  80. package/types/server/renderer/document/index.d.ts +0 -2
  81. package/types/server/renderer/extract.d.ts +0 -18
  82. package/types/server/renderer/handler.d.ts +0 -6
  83. package/types/server/renderer/index.d.ts +0 -2
  84. package/types/server/renderer/render.d.ts +0 -38
  85. package/types/server/renderer/userAgentUtil.d.ts +0 -1
  86. package/types/store/index.d.ts +0 -11
  87. package/types/store/index.dev.d.ts +0 -8
  88. package/types/store/index.prod.d.ts +0 -8
  89. package/types/webpack/babel-plugins/remove-client.plugin.d.ts +0 -10
  90. package/types/webpack/babel-plugins/remove-ssr.plugin.d.ts +0 -10
  91. package/types/webpack/babel.config.client.d.ts +0 -21
  92. package/types/webpack/babel.config.d.ts +0 -16
  93. package/types/webpack/babel.config.ssr.d.ts +0 -21
  94. package/types/webpack/base.babel.d.ts +0 -184
  95. package/types/webpack/development.client.babel.d.ts +0 -1
  96. package/types/webpack/plugins/mime-types.d.ts +0 -78
  97. package/types/webpack/plugins/route-manifest-plugin.d.ts +0 -1
  98. package/types/webpack/plugins/upload-assets-plugin.d.ts +0 -1
  99. package/types/webpack/production.client.babel.d.ts +0 -174
  100. package/types/webpack/production.ssr.babel.d.ts +0 -2
  101. package/types/webpack/scssParams.d.ts +0 -2
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getUserAgentDetails = void 0;
7
+ var _uaParserJs = _interopRequireDefault(require("ua-parser-js"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ const googleBots = {
10
+ "APIs-Google": "APIs-Google",
11
+ AdSense: "Mediapartners-Google",
12
+ "AdsBot Mobile Web Android": "AdsBot-Google-Mobile",
13
+ "AdsBot Mobile Web": "AdsBot-Google-Mobile",
14
+ AdsBot: "AdsBot-Google",
15
+ "Mobile AdSense": "Mediapartners-Google",
16
+ "Mobile Apps Android": "AdsBot-Google-Mobile-Apps",
17
+ Feedfetcher: "FeedFetcher-Google",
18
+ "Google Read Aloud": "Google-Read-Aloud",
19
+ "Duplex on the Web": "DuplexWeb-Google",
20
+ "Google Favicon": "Google Favicon",
21
+ "Web Light": "googleweblight",
22
+ "Amp crawler": "Google-AMPHTM",
23
+ Googlebot: "Googlebot"
24
+ };
25
+
26
+ /**
27
+ * check if user agent contains bot data
28
+ * @param {string} ua - user agent
29
+ * @return {string|null}
30
+ */
31
+ const getGoogleBot = ua => {
32
+ for (let key in googleBots) {
33
+ if (ua.includes(googleBots[key])) return key;
34
+ }
35
+ return null;
36
+ };
37
+
38
+ /**
39
+ * returns object which contains google bot and user-agent info
40
+ * @param {string} ua - user agent
41
+ * @return {object} - returns user agent
42
+ */
43
+ const getUserAgentDetails = ua => {
44
+ const agentDetails = (0, _uaParserJs.default)(ua);
45
+ const googleBot = getGoogleBot(ua);
46
+ return {
47
+ ...agentDetails,
48
+ googleBot
49
+ };
50
+ };
51
+ exports.getUserAgentDetails = getUserAgentDetails;
@@ -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 !== 'function') throw new Error("preServerInit should be function present in server/index.js");
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 !== 'function') throw new Error("addMiddlewares should be function present in server/server.js");
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 !== 'function') throw new Error("reducer should present in src/js/containers/App/reducer");
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 !== 'object') throw new Error("config object should be exported from config folder inside your project root directory");
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 !== 'object') throw new Error("package.json should be defined in project root directory");
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 !== 'object') throw new Error("moduleAliases named object should be exported from package.json");
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 !== 'function') throw new Error("configureStore should be function exported from src/js/store/index.js");
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/routers/index.js");
73
- if (typeof fn !== 'function') throw new Error("getRoutes should be function exported from src/js/routers/index.js");
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 !== 'function') throw new Error("document should be a react component exported from server/document.js");
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);
@@ -7,7 +7,7 @@ exports.default = _default;
7
7
  /**
8
8
  * @description babel plugin used to remove unwanted code from the build.
9
9
  * @return babel plugin object
10
- */
10
+ */
11
11
  function _default() {
12
12
  return {
13
13
  name: "ast-transform",
@@ -7,7 +7,7 @@ exports.default = _default;
7
7
  /**
8
8
  * @description babel plugin used to remove unwanted code from the build.
9
9
  * @return babel plugin object
10
- */
10
+ */
11
11
  function _default() {
12
12
  return {
13
13
  name: "ast-transform",
@@ -11,13 +11,13 @@ var _default = exports.default = {
11
11
  browsers: "last 2 versions"
12
12
  }
13
13
  }], "@babel/preset-react"],
14
- plugins: ["@babel/plugin-proposal-object-rest-spread", "@babel/plugin-transform-react-jsx", "transform-class-properties", "transform-export-extensions", "syntax-dynamic-import", "@loadable/babel-plugin"],
14
+ plugins: ["@loadable/babel-plugin"],
15
15
  env: {
16
16
  production: {
17
17
  plugins: [require("./babel-plugins/remove-ssr.plugin").default, "transform-react-remove-prop-types"]
18
18
  },
19
- "test": {
20
- "presets": ["@babel/preset-react"]
19
+ test: {
20
+ presets: ["@babel/preset-react"]
21
21
  }
22
22
  },
23
23
  ignore: ["__TEST__"]
@@ -11,7 +11,7 @@ var _default = exports.default = {
11
11
  node: "current"
12
12
  }
13
13
  }], "@babel/preset-react"],
14
- plugins: ["@babel/plugin-proposal-object-rest-spread", "@babel/plugin-transform-react-jsx", "transform-class-properties", "transform-export-extensions", "syntax-dynamic-import", "@loadable/babel-plugin"],
14
+ plugins: ["@loadable/babel-plugin"],
15
15
  env: {
16
16
  development: {
17
17
  plugins: ["react-refresh/babel"]
@@ -16,14 +16,14 @@ var _loadEnvironmentVariables = _interopRequireDefault(require("../scripts/loadE
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
  const catalystConfig = require(_path.default.resolve(__dirname, "..", "config.json"));
18
18
  const {
19
- enableDynamicImports,
20
- clientEnv
21
- } = require(`${process.env.src_path}/config`);
19
+ CLIENT_ENV_VARIABLES: clientEnv,
20
+ ANALYZE_BUNDLE
21
+ } = require(`${process.env.src_path}/config/config.json`);
22
22
  const {
23
23
  _moduleAliases
24
24
  } = require(`${process.env.src_path}/package.json`);
25
25
  (0, _loadEnvironmentVariables.default)();
26
- const isDev = process.env.NODE_ENV !== "production";
26
+ const isDev = process.env.NODE_ENV === "development";
27
27
  const isSSR = !!process.env.SSR || false;
28
28
  const basePlugins = exports.basePlugins = [new _webpackPlugin.default({
29
29
  filename: "loadable-stats.json",
@@ -36,45 +36,53 @@ new _webpack.default.DefinePlugin({
36
36
  "process.env": ([...clientEnv, ...Object.keys(process.env)] || []).reduce((clientEnvMap, env) => {
37
37
  clientEnvMap[env] = JSON.stringify(process.env[env]);
38
38
  return clientEnvMap;
39
- }, {}),
40
- // Loadable dynamic rendring config
41
- "process.loadableConfig": {
42
- CLIENT_ONLY_RENDER: process.env["CLIENT_ONLY_RENDER"] === "true",
43
- SERVER_SIDE_RENDER: process.env["SERVER_SIDE_RENDER"] === "true"
44
- }
39
+ }, {})
45
40
  }),
46
41
  // ** This is used to analyze bundle size.
47
- catalystConfig.analyzeBundle && new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
48
- generateStatsFile: true
42
+ ANALYZE_BUNDLE && new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
43
+ generateStatsFile: ANALYZE_BUNDLE
49
44
  }), new _webpack.default.IgnorePlugin({
50
45
  resourceRegExp: /^\.\/locale$/,
51
46
  contextRegExp: /moment$/
52
47
  })];
53
- let publicPath = process.env.PUBLIC_ASSET_PATH || "/";
48
+ const {
49
+ IS_DEV_COMMAND,
50
+ PUBLIC_STATIC_ASSET_URL,
51
+ PUBLIC_STATIC_ASSET_PATH,
52
+ WEBPACK_DEV_SERVER_HOSTNAME,
53
+ WEBPACK_DEV_SERVER_PORT,
54
+ NODE_SERVER_HOSTNAME,
55
+ NODE_SERVER_PORT
56
+ } = process.env;
57
+ let publicPath = isDev ? `http://${WEBPACK_DEV_SERVER_HOSTNAME}:${WEBPACK_DEV_SERVER_PORT}/` : `${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;
58
+
59
+ // serves assets from local on running devBuild and devServe command
60
+ if (JSON.parse(IS_DEV_COMMAND) && !isDev) {
61
+ publicPath = `http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/assets/`;
62
+ }
54
63
  var _default = exports.default = {
55
64
  context: _path.default.resolve(process.env.src_path),
56
65
  mode: isDev ? "development" : "production",
57
66
  entry: {
58
67
  app: [_path.default.resolve(process.env.src_path, "./client/index.js")]
59
68
  },
60
- // TODO this will be moved each config
61
-
62
69
  output: {
63
- path: _path.default.join(process.env.src_path, process.env.PUBLIC_OUTPUT_PATH),
64
- filename: catalystConfig.chunkFileNameDev,
70
+ path: _path.default.join(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`),
71
+ chunkFilename: process.env.NODE_ENV === "development" ? catalystConfig.chunkFileNameDev : catalystConfig.chunkFileNameProd,
65
72
  publicPath: publicPath,
66
- chunkFilename: enableDynamicImports ? catalystConfig.chunkFileNameDev : undefined
73
+ chunkFilename: process.env.NODE_ENV === "development" ? catalystConfig.chunkFileNameDev : catalystConfig.chunkFileNameProd
67
74
  },
68
75
  resolve: {
76
+ fallback: {
77
+ url: require.resolve("url")
78
+ },
69
79
  extensions: [".js", ".jsx", ".scss"],
70
80
  alias: Object.keys(_moduleAliases || {}).reduce((moduleEnvMap, alias) => {
71
81
  moduleEnvMap[alias] = _path.default.join(process.env.src_path, ..._moduleAliases[alias].split("/"));
72
82
  return moduleEnvMap;
73
83
  }, {})
74
84
  },
75
- // TODO common plugins here. Rest will be moved to each file
76
85
  plugins: basePlugins,
77
- // TODO module rules will be here. and should be common for all
78
86
  module: {
79
87
  rules: [{
80
88
  test: /\.jsx$|\.js$/,
@@ -84,9 +92,7 @@ var _default = exports.default = {
84
92
  options: isSSR ? _babelConfig2.default : _babelConfig.default
85
93
  }
86
94
  }, {
87
- // For all .scss files that should be modularized. This should exclude
88
- // anything inside node_modules and everything inside src/css/base
89
- // since they should be globally scoped.
95
+ // This loader processes all the .scss files that should be modularized. This should exclude anything inside node_modules and everything inside src/css/base since they should be globally scoped.
90
96
  test: /\.scss$/,
91
97
  exclude: [_path.default.resolve(process.env.src_path, "./node_modules"), _path.default.resolve(process.env.src_path, "./src/static/css/base")],
92
98
  use: [isDev && "css-hot-loader", !isSSR && _miniCssExtractPlugin.default.loader, {
@@ -96,15 +102,14 @@ var _default = exports.default = {
96
102
  mode: "local",
97
103
  exportOnlyLocals: !isDev && isSSR,
98
104
  localIdentName: isDev ? catalystConfig.cssModulesIdentifierDev : catalystConfig.cssModulesIdentifierProd
99
- },
100
- importLoaders: 0
105
+ }
101
106
  }
102
107
  }, {
103
108
  loader: "postcss-loader"
104
109
  }, {
105
110
  loader: "sass-loader",
106
111
  options: {
107
- additionalData: "$font_url: " + (0, _scssParams.fontUrl)() + ";" + "$url_for: " + (0, _scssParams.urlFor)() + ";"
112
+ additionalData: "$font_url: " + (0, _scssParams.fontUrl)() + ";" + "$url_for: " + (0, _scssParams.imageUrl)() + ";"
108
113
  }
109
114
  }, {
110
115
  loader: "sass-resources-loader",
@@ -113,19 +118,17 @@ var _default = exports.default = {
113
118
  }
114
119
  }]
115
120
  }, {
116
- // in local dev, client request app.css whoever in prod this css is injected in the doc sent from the server
117
- // for .scss modules that need to be available globally, we don't pass
118
- // the files through css-loader to be modularized.
121
+ // In development mode, client request app.css ,which has all the css in node_modules and src/static/css/base, This is served by webpack-dev-server. However in prod this css is injected in the doc sent from the server and needs to be global, so we don't pass the files through css-loader to be modularized.
119
122
  test: /\.scss$/,
120
123
  include: [_path.default.resolve(process.env.src_path, "./node_modules"), _path.default.resolve(process.env.src_path, "./src/static/css/base")],
121
- use: ["css-hot-loader", !isSSR && _miniCssExtractPlugin.default.loader, {
124
+ use: [isDev && "css-hot-loader", !isSSR && _miniCssExtractPlugin.default.loader, {
122
125
  loader: "css-loader"
123
126
  }, {
124
127
  loader: "postcss-loader"
125
128
  }, {
126
129
  loader: "sass-loader",
127
130
  options: {
128
- additionalData: "$font_url: " + (0, _scssParams.fontUrl)() + ";" + "$url_for: " + (0, _scssParams.urlFor)() + ";"
131
+ additionalData: "$font_url: " + (0, _scssParams.fontUrl)() + ";" + "$url_for: " + (0, _scssParams.imageUrl)() + ";"
129
132
  }
130
133
  }, {
131
134
  loader: "sass-resources-loader",
@@ -136,9 +139,7 @@ var _default = exports.default = {
136
139
  }, {
137
140
  test: /\.css$/,
138
141
  use: [!isSSR && _miniCssExtractPlugin.default.loader, "css-loader", "postcss-loader"]
139
- },
140
- // TODO replace them with asset/module
141
- {
142
+ }, {
142
143
  test: /\.(png|jpg|gif|jpeg|ico?)$/,
143
144
  use: ["url-loader?limit=10240", "img-loader"]
144
145
  }, {
@@ -146,7 +147,7 @@ var _default = exports.default = {
146
147
  issuer: /\.[jt]sx?$/,
147
148
  use: ["@svgr/webpack", "url-loader?limit=10240", "img-loader"]
148
149
  }, {
149
- // Load fonts using file-loader
150
+ // This loader loads fonts in src/static/fonts using file-loader
150
151
  test: /\.(ttf|eot|woff2|json?)$/,
151
152
  use: [{
152
153
  loader: "url-loader",
@@ -156,7 +157,7 @@ var _default = exports.default = {
156
157
  }
157
158
  }, "file-loader"]
158
159
  }, {
159
- // Load html files
160
+ // This loader loads html files
160
161
  test: /\.html$/,
161
162
  use: [{
162
163
  loader: "html-loader",
@@ -11,19 +11,21 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
  /* eslint-disable no-console */
12
12
 
13
13
  const {
14
- DEV_SERVER_HOST_URL
14
+ WEBPACK_DEV_SERVER_PORT,
15
+ WEBPACK_DEV_SERVER_HOSTNAME,
16
+ NODE_SERVER_PORT,
17
+ NODE_SERVER_HOSTNAME
15
18
  } = process.env;
16
19
  const catalystConfig = require(_path.default.resolve(__dirname, "..", "config.json"));
17
20
  const plugins = require(_path.default.join(process.env.src_path, "webpackConfig.js"));
18
21
  const webpackConfig = (0, _webpackMerge.default)(_baseBabel.default, {
19
22
  devtool: "inline-source-map",
23
+ stats: "minimal",
20
24
  plugins: [new _reactRefreshWebpackPlugin.default({
21
25
  overlay: {
22
26
  entry: false
23
27
  }
24
- }),
25
- // TODO added in client and dev build
26
- new _miniCssExtractPlugin.default({
28
+ }), new _miniCssExtractPlugin.default({
27
29
  filename: catalystConfig.cssChunkFileName,
28
30
  ignoreOrder: true
29
31
  }), ...plugins.developmentPlugins].filter(Boolean),
@@ -33,7 +35,7 @@ const webpackConfig = (0, _webpackMerge.default)(_baseBabel.default, {
33
35
  splitChunks: {
34
36
  cacheGroups: {
35
37
  commonVendor: {
36
- test: /[\\/]node_modules[\\/](react|react-dom|react-redux|react-router|react-router-dom|redux|redux-thunk|axios|react-loadable-visibility|react-helmet-async|react-google-recaptcha|normalize.css|react-detect-offline|react-side-effect|react-fast-compare|react-async-script|babel|history)[\\/]/,
38
+ test: /[\\/]node_modules[\\/](react|react-dom|react-redux|react-router|react-router-dom|redux|redux-thunk|axios|react-loadable-visibility|react-helmet-async|react-fast-compare|react-async-script|babel|@loadable\/component|catalyst)[\\/]/,
37
39
  name: "commonVendor",
38
40
  minSize: 30000
39
41
  },
@@ -57,12 +59,14 @@ const webpackConfig = (0, _webpackMerge.default)(_baseBabel.default, {
57
59
  });
58
60
  console.info("Firing up catalyst dev server...\n");
59
61
  let devServer = new _webpackDevServer.default({
60
- port: process.env.DEV_SERVER_PORT,
62
+ port: WEBPACK_DEV_SERVER_PORT,
63
+ host: WEBPACK_DEV_SERVER_HOSTNAME,
61
64
  static: {
62
65
  publicPath: webpackConfig.output.publicPath
63
66
  },
64
67
  hot: true,
65
68
  historyApiFallback: true,
69
+ open: [`http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}`],
66
70
  headers: {
67
71
  "Access-Control-Allow-Origin": "*"
68
72
  },
@@ -73,10 +77,9 @@ let devServer = new _webpackDevServer.default({
73
77
  warnings: false,
74
78
  runtimeErrors: false
75
79
  },
76
- progress: true,
77
80
  reconnect: true
78
81
  }
79
82
  }, (0, _webpack.default)(webpackConfig));
80
83
  devServer.startCallback(() => {
81
- console.info(`Webpack dev server mounted at ${DEV_SERVER_HOST_URL}.`);
84
+ console.info(`Webpack dev server mounted at http://${WEBPACK_DEV_SERVER_HOSTNAME}:${WEBPACK_DEV_SERVER_PORT}.`);
82
85
  });
@@ -15,7 +15,6 @@ const {
15
15
  } = require("webpack-merge");
16
16
  const plugins = require(_path.default.join(process.env.src_path, "webpackConfig.js"));
17
17
  const catalystConfig = require(_path.default.resolve(__dirname, "..", "config.json"));
18
- const isSSR = !!process.env.SSR || false;
19
18
  const clientConfig = mergeWithCustomize({
20
19
  customizeArray: customizeArray({
21
20
  entry: "prepend",
@@ -36,7 +35,7 @@ const clientConfig = mergeWithCustomize({
36
35
  cacheGroups: {
37
36
  commonVendor: {
38
37
  chunks: "all",
39
- test: /[\\/]node_modules[\\/](react|react-dom|react-redux|react-router|react-router-dom|redux|redux-thunk|axios|react-loadable-visibility|react-helmet-async|react-google-recaptcha|normalize.css|react-detect-offline|react-side-effect|react-fast-compare|react-async-script|babel|history|@tata1mg|@loadable\/component|framer-motion|pwa|)[\\/]/,
38
+ test: /[\\/]node_modules[\\/](react|react-dom|react-redux|react-router|react-router-dom|redux|redux-thunk|axios|react-loadable-visibility|react-helmet-async|react-fast-compare|react-async-script|babel|@loadable\/component|catalyst)[\\/]/,
40
39
  name: "commonVendor",
41
40
  minSize: 400000,
42
41
  maxSize: 400000
@@ -36,7 +36,7 @@ const ssrConfig = mergeWithCustomize({
36
36
  name: false
37
37
  }
38
38
  },
39
- plugins: [...plugins.ssrPrugins],
39
+ plugins: [...plugins.ssrPlugins],
40
40
  target: "node",
41
41
  entry: {
42
42
  handler: _path.default.resolve(__dirname, "..", "./server/renderer/handler.js")
@@ -52,8 +52,8 @@ const ssrConfig = mergeWithCustomize({
52
52
  modulesDir: _path.default.join(rootWorkspacePath.path, "./node_modules")
53
53
  })],
54
54
  output: {
55
- path: _path.default.join(process.env.src_path, process.env.OUTPUT_PATH, "renderer"),
56
- chunkFilename: catalystConfig.chunkFileNameDev,
55
+ path: _path.default.join(process.env.src_path, process.env.BUILD_OUTPUT_PATH, "/renderer"),
56
+ chunkFilename: catalystConfig.chunkFileNameProd,
57
57
  filename: "handler.js",
58
58
  libraryTarget: "commonjs"
59
59
  }
@@ -3,29 +3,49 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.urlFor = exports.fontUrl = void 0;
6
+ exports.imageUrl = exports.fontUrl = void 0;
7
7
  /**
8
8
  * @description generate assets url according to enviorment
9
9
  * @returns returns path required for loading assets according to enviorment
10
- */
11
- const urlFor = () => {
12
- const isDev = process.env.NODE_ENV !== "production",
13
- isLocalBuild = process.env.BUILD_ENV === "localBuild";
14
- const localPath = JSON.stringify(`${process.env.SERVER_PATH + process.env.LOCAL_ASSET_PATH}`);
15
- const cdnPath = JSON.stringify(`${process.env.PUBLIC_ASSET_PATH}images/`);
16
- return isDev || isLocalBuild ? localPath : cdnPath;
10
+ */
11
+ const imageUrl = () => {
12
+ const {
13
+ PUBLIC_STATIC_ASSET_URL,
14
+ PUBLIC_STATIC_ASSET_PATH,
15
+ IS_DEV_COMMAND,
16
+ NODE_SERVER_HOSTNAME,
17
+ NODE_SERVER_PORT
18
+ } = process.env;
19
+ let publicPath = `${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;
20
+
21
+ // serves assets from localhost on running devBuild and devServe command
22
+ if (JSON.parse(IS_DEV_COMMAND)) {
23
+ publicPath = `http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/${PUBLIC_STATIC_ASSET_PATH}`;
24
+ }
25
+ const imagePath = JSON.stringify(`${publicPath}images/`);
26
+ return imagePath;
17
27
  };
18
28
 
19
29
  /**
20
30
  * @description generate assets font url according to enviorment
21
31
  * @returns returns path required for loading fonts according to enviorment
22
- */
23
- exports.urlFor = urlFor;
32
+ */
33
+ exports.imageUrl = imageUrl;
24
34
  const fontUrl = () => {
25
- const isDev = process.env.NODE_ENV !== "production",
26
- isLocalBuild = process.env.BUILD_ENV === "localBuild";
27
- const localPath = JSON.stringify(`${process.env.SERVER_PATH + process.env.LOCAL_ASSET_PATH}`);
28
- const cdnPath = JSON.stringify(`${process.env.PUBLIC_ASSET_PATH}fonts/`);
29
- return isDev || isLocalBuild ? localPath : cdnPath;
35
+ const {
36
+ PUBLIC_STATIC_ASSET_URL,
37
+ PUBLIC_STATIC_ASSET_PATH,
38
+ IS_DEV_COMMAND,
39
+ NODE_SERVER_HOSTNAME,
40
+ NODE_SERVER_PORT
41
+ } = process.env;
42
+ let publicPath = `${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;
43
+
44
+ // serves assets from localhost on running devBuild and devServe command
45
+ if (JSON.parse(IS_DEV_COMMAND)) {
46
+ publicPath = `http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/${PUBLIC_STATIC_ASSET_PATH}`;
47
+ }
48
+ const fontPath = JSON.stringify(`${publicPath}fonts/`);
49
+ return fontPath;
30
50
  };
31
51
  exports.fontUrl = fontUrl;
package/.prettierignore DELETED
@@ -1,2 +0,0 @@
1
- **/*.html
2
-
package/.prettierrc.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "trailingComma": "es5",
3
- "tabWidth": 4,
4
- "semi": false,
5
- "arrowParens": "always",
6
- "printWidth": 110
7
- }
package/checkVersion.js DELETED
@@ -1,3 +0,0 @@
1
- if(process.versions.node.split(".")[0]<20){
2
- console.error('\x1b[31m%s\x1b[0m', 'use node version >=20');
3
- }
package/config/config.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = exports.default = {
8
- "S3_BUCKET": "stagassets.1mg.com",
9
- "S3_FOLDER": "pwa-app",
10
- "CDN_ASSET_PATH": "https://stagstatic.1mg.com",
11
- "APPLICATION_PORT": "3005",
12
- "APPLICATION_BASE_URL": "http://localhost:3005",
13
- "SERVER_PATH": "http://localhost:3005",
14
- "OUTPUT_PATH": "build",
15
- "PUBLIC_OUTPUT_PATH": "build/public",
16
- "PUBLIC_ASSET_PATH": "http://localhost:3006/assets/",
17
- "LOCAL_ASSET_PATH": "/assets/",
18
- "EXTERNAL_BASE_URL": "http://localhost:3005",
19
- "DEV_SERVER_PORT": 3006,
20
- "DEV_SERVER_HOSTNAME": "localhost",
21
- "DEV_SERVER_HOST_URL": "http://localhost:3006",
22
- "ENV_NAME": "local",
23
- "BUILD_ENV": ""
24
- };