@zohodesk/react-cli 1.1.1 → 1.1.2-9.exp.3

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 (78) hide show
  1. package/.vscode/settings.json +25 -0
  2. package/README.md +446 -35
  3. package/bin/cli.js +17 -52
  4. package/docs/CustomChunks.md +12 -9
  5. package/docs/MarkdownParser.md +18 -0
  6. package/docs/ReactLive.md +8 -0
  7. package/docs/ValueReplacer.md +27 -0
  8. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  9. package/lib/babel/cmjs-plugins-presets.js +36 -7
  10. package/lib/babel/es-plugins-presets.js +45 -16
  11. package/lib/common/runPreProcess.js +71 -0
  12. package/lib/common/splitChunks.js +65 -45
  13. package/lib/common/testPattern.js +9 -9
  14. package/lib/configs/jest.config.js +4 -4
  15. package/lib/configs/libAlias.js +36 -2
  16. package/lib/configs/resolvers.js +7 -4
  17. package/lib/configs/webpack.css.umd.config.js +3 -2
  18. package/lib/configs/webpack.dev.config.js +28 -8
  19. package/lib/configs/webpack.docs.config.js +10 -5
  20. package/lib/configs/webpack.impact.config.js +9 -4
  21. package/lib/configs/webpack.prod.config.js +32 -10
  22. package/lib/constants.js +3 -3
  23. package/lib/deprecationLogger.js +40 -0
  24. package/lib/jest/preProcessors/jsPreprocessor.js +27 -2
  25. package/lib/loaderUtils/configsAssetsLoaders.js +1 -1
  26. package/lib/loaderUtils/getCSSLoaders.js +32 -8
  27. package/lib/loaderUtils/getDevJsLoaders.js +8 -2
  28. package/lib/loaders/__test__/markdownLoader.spec.js +145 -0
  29. package/lib/loaders/composeLoader.js +140 -14
  30. package/lib/loaders/docsLoader.js +5 -2
  31. package/lib/loaders/enhancedReactLiveConverter.js +151 -0
  32. package/lib/loaders/markdownLoader.js +71 -0
  33. package/lib/loaders/workerLoader.js +37 -22
  34. package/lib/logger.js +7 -0
  35. package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
  36. package/lib/pluginUtils/getDevPlugins.js +24 -8
  37. package/lib/pluginUtils/getProdPlugins.js +34 -6
  38. package/lib/plugins/CssOrderControlPlugin.js +36 -0
  39. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
  40. package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
  41. package/lib/plugins/EventsHandlingPlugin.js +34 -0
  42. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
  43. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +4 -1
  44. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +14 -0
  45. package/lib/plugins/ReportGeneratePlugin.js +8 -6
  46. package/lib/plugins/ResourceHintsPlugin.js +13 -3
  47. package/lib/plugins/StatsPlugin.js +82 -0
  48. package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
  49. package/lib/plugins/utils/fileHandling.js +36 -51
  50. package/lib/plugins/variableConvertorUtils.js +4 -2
  51. package/lib/postcss-plugins/ValueReplacer.js +7 -17
  52. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
  53. package/lib/postcss-plugins/variableModificationPlugin/index.js +70 -18
  54. package/lib/schemas/index.js +67 -39
  55. package/lib/servers/getCliPath.js +3 -5
  56. package/lib/servers/requireLocalOrGlobal.js +1 -1
  57. package/lib/utils/cssClassNameGenerate.js +43 -5
  58. package/lib/utils/deprecationSupport.js +134 -0
  59. package/lib/utils/getFileType.js +1 -1
  60. package/lib/utils/getOptions.js +31 -69
  61. package/lib/utils/getServerURL.js +7 -2
  62. package/lib/utils/index.js +27 -11
  63. package/lib/utils/initPreCommitHook.js +5 -5
  64. package/lib/utils/log.js +11 -0
  65. package/lib/utils/object-manipulation.js +88 -0
  66. package/lib/utils/pullOrigin.js +3 -3
  67. package/lib/utils/reinstallDependencies.js +3 -3
  68. package/lib/utils/switchBranch.js +4 -2
  69. package/lib/utils/typeCheck.js +10 -0
  70. package/lib/utils/variableConverter.js +26 -11
  71. package/npm-shrinkwrap.json +929 -39
  72. package/package.json +12 -4
  73. package/templates/docs/all.html +1 -0
  74. package/templates/docs/component.html +1 -0
  75. package/templates/docs/components.html +1 -0
  76. package/templates/docs/css/markdown.css +202 -0
  77. package/templates/docs/css/style.css +136 -169
  78. package/templates/docs/index.html +796 -632
package/bin/cli.js CHANGED
@@ -1,15 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require('path');
4
- const { existsSync } = require('fs');
5
- const { spawnSync: _spawnSync, spawn } = require('child_process');
6
- const { getOptions } = require('../lib/utils/index.js');
4
+ const { spawnSync: _spawnSync, execSync } = require('child_process');
5
+ const getOptions = require('../lib/utils/getOptions.js').default;
7
6
 
8
- const { log } = require('../lib/utils');
7
+ const { log } = require('../lib/utils/log.js');
9
8
  const { getCliPath } = require('../lib/servers/getCliPath.js');
9
+ const { runPreProcess } = require('../lib/common/runPreProcess.js');
10
10
  //initPreCommitHook();
11
11
 
12
- const options = getOptions();
12
+ const [, , option] = process.argv;
13
+ const args = process.argv.slice(3);
14
+ const appPath = process.cwd();
15
+
16
+ const options = getOptions({ start: true, build: true, docs: true }[option]);
13
17
 
14
18
  function spawnSync(...args) {
15
19
  const result = _spawnSync(...args);
@@ -20,7 +24,6 @@ function spawnSync(...args) {
20
24
  }
21
25
 
22
26
  const { esLint: esLintOptions } = options || {};
23
- const { preprocess } = options;
24
27
  const {
25
28
  ignoreFilePaths: esLintIgnorePaths,
26
29
  fix: esLintFix,
@@ -28,10 +31,6 @@ const {
28
31
  reportPath: reportPath
29
32
  } = esLintOptions || {};
30
33
 
31
- const [, , option] = process.argv;
32
- const args = process.argv.slice(3);
33
- const appPath = process.cwd();
34
-
35
34
  const webpack = getCliPath('webpack');
36
35
 
37
36
  const nodemon = getCliPath('nodemon');
@@ -39,49 +38,10 @@ const babel = getCliPath('babel');
39
38
  const propertyToJson = getCliPath('propertyToJson');
40
39
  const esLint = getCliPath('eslint');
41
40
 
42
- const preprocesserPath = preprocess.runner
43
- ? path.join(process.cwd(), preprocess.runner)
44
- : '';
45
- const preprocessCli = preprocess.stopNodemon ? 'node' : nodemon;
46
- if (preprocesserPath && existsSync(preprocesserPath)) {
47
- // eslint-disable-next-line default-case
48
- switch (option) {
49
- case 'start':
50
- case 'docs':
51
- spawn(preprocessCli, [preprocesserPath], {
52
- stdio: 'inherit',
53
- cwd: path.parse(preprocesserPath).dir
54
- });
55
- // NOTE: it's ok if we not close this here
56
- // Because when node server stops this program willbe closed So this nodemon will be killed as well
57
- break;
58
- case 'nowatchstart':
59
- case 'devbuild':
60
- case 'build:library:es':
61
- case 'build:component:es':
62
- case 'build:library:cmjs':
63
- case 'build:component:cmjs':
64
- spawnSync('node', [preprocesserPath], {
65
- stdio: 'inherit',
66
- cwd: preprocesserPath.slice(0, preprocesserPath.lastIndexOf('/') + 1)
67
- });
68
- break;
69
- }
70
- }
41
+ runPreProcess({ options, option, nodemon, spawnSync });
71
42
 
72
43
  let result;
73
44
  switch (option) {
74
- case 'preprocessor':
75
- if (preprocesserPath && existsSync(preprocesserPath)) {
76
- result = spawnSync(preprocessCli, [preprocesserPath], {
77
- stdio: 'inherit',
78
- cwd: preprocesserPath.slice(0, preprocesserPath.lastIndexOf('/') + 1)
79
- });
80
- process.exit(result.status);
81
- } else {
82
- console.error(`preProcessor not exists ${preprocesserPath}`);
83
- }
84
- break;
85
45
  case 'lint-setup': {
86
46
  result = spawnSync(
87
47
  'node',
@@ -270,7 +230,7 @@ switch (option) {
270
230
  require.resolve('../lib/servers/mockserver.js'),
271
231
  '--delay',
272
232
  '2500ms',
273
- 'watch',
233
+ '--watch',
274
234
  `${appPath + path.sep}mockapi`
275
235
  ].concat(args),
276
236
  { stdio: 'inherit' }
@@ -340,6 +300,8 @@ switch (option) {
340
300
  'src',
341
301
  '-d',
342
302
  'lib',
303
+ '--extensions',
304
+ '.js,.ts,.tsx',
343
305
  `--presets=${require.resolve('../lib/babel/cmjs-plugins-presets.js')}`,
344
306
  '--copy-files'
345
307
  ].concat(args),
@@ -356,6 +318,8 @@ switch (option) {
356
318
  'src',
357
319
  '--out-dir',
358
320
  'es',
321
+ '--extensions',
322
+ '.js,.ts,.tsx',
359
323
  `--presets=${require.resolve('../lib/babel/es-plugins-presets.js')}`,
360
324
  '--copy-files'
361
325
  ].concat(args),
@@ -477,8 +441,9 @@ switch (option) {
477
441
  case '--v':
478
442
  case '-v':
479
443
  log(`@zohodesk/react-cli v${require('../package.json').version}`);
444
+ log(`Node Js Version : ${process.version}`);
445
+ log(`Npm Version : ${execSync('npm --version')}`);
480
446
  break;
481
-
482
447
  default:
483
448
  log(`react-cli > Unknown option "${option}"`);
484
449
  log('react-cli app <appName>');
@@ -4,23 +4,26 @@ In react-cli we provide options to create custom chunks.
4
4
  This Custom Chunk Option is array of Object
5
5
  that Object keys are
6
6
 
7
- - `pattern` regex pattern as string
8
- - `name` chunk name
9
- - `size` is count which is minmum chunk dublicated or need in chunks
7
+ - `pattern` **{ String | Function | Array<String> }** regex pattern as string and custom logic to split chunks can be defined using function
8
+ - `name` **{ String }** chunk name
9
+ - `size` **{ Number }** is count which is minimum chunk duplicated or need in chunks
10
10
 
11
11
  > Since 0.0.1-exp.164.1
12
12
 
13
13
  extra features in custom chunks :-
14
14
  for more details [SplitChunkPlugin](https://webpack.js.org/plugins/split-chunks-plugin/) webpack
15
15
 
16
- - `minChunks`: `minChunks` is alies of `size` default value is `2`,
17
- - `rules`: `rules` is same as `pattern` with some easy hooks
16
+ - `minChunks`: `minChunks` is alias of `size` default value is `2`,
17
+ - `rules`: `rules` is same as `pattern` with some easy hooks **(removed after v1.1.5)**
18
18
  - use `/` for both windows and linux we will replace internally
19
19
  - for `.*` we need to use `*`
20
20
  - we can consider rules as regex when the `rules-string` has any of these `*`, `^`, `$`. So if you want regex then kindly use `*` in your `rules-string` for force regex
21
21
  - `chunks`: by this option we can specify , default value is `all`,
22
22
  - `priority`: priority default value is `-10 * (index + 2)`,
23
- - `enforce`: enforce default value is true,
24
- - `maxSize`: maxSize, default value is 0,
25
- - `minSize`: minSize, default value is 20000,
26
- includeDepenency: includeDepenency default value is false
23
+ - `enforce`: enforce default value is `true`,
24
+ - `maxSize`: maxSize, default value is `0`,
25
+ - `minSize`: minSize, default value is `20000`,
26
+ - `reuseExistingChunk` If the current chunk contains modules already split out from the main bundle, it will be reused instead of a new one being generated. This can affect the resulting file name of the chunk.
27
+ - `automaticNamePrefix` with this you can specify for chunks created through that specified config. default value `''`.
28
+ - `cacheGroupName`: `cacheGroupName` is alias of `name`, But it won't work as chunk name, instead it will just work as key in cacheGroup.
29
+ <!-- includeDependency: includeDependency default value is `false` -->
@@ -0,0 +1,18 @@
1
+
2
+ ----> markdownParser <----
3
+
4
+ 1. Markdown parser allows us to write Documentation using Markdown language inside the Javascript file
5
+ 2. This will converts the snippets to HTML tag.
6
+ 3. We can implement this only inside the particular syntax which is metioned below.
7
+ 4. We can enable/disable this feature by `npm run docs --markdown_parser=true/false` default value will be `true`.
8
+ 5. Also we can enable/disable this feature by adding `enableMDParser` key inside the package.json under the `docs`.
9
+
10
+ ### syntax
11
+ ```
12
+ /* MD:START
13
+ # Hello World
14
+ MD:END */
15
+ ```
16
+
17
+ # v1.1.7 update:
18
+ * Markdown Parser feature implemented.
package/docs/ReactLive.md CHANGED
@@ -8,3 +8,11 @@
8
8
 
9
9
  # v1.1.0 update:
10
10
  * ReactLive feature implemented.
11
+
12
+ # v1.1.2 update:
13
+
14
+ * ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
15
+
16
+ # v1.1.20 update:
17
+
18
+ * enhancedReactLiveConverter.js added and imported in docLoader file
@@ -58,3 +58,30 @@ new option `valueReplacer` added for replace css property value while build runn
58
58
  font: zdf-rCallBar_1 !important;
59
59
  }
60
60
  ```
61
+
62
+
63
+ If we need the exact word to be considered for replacement ( that is, if value is `text` and only if the value is `text` and not `text_cursor` or `cursortext` for example, the conversion happens ) we have to use `^` before the word and `$` after the word in the key.
64
+
65
+ # For Example :
66
+ {
67
+ valueReplacer: [
68
+ {
69
+ "props": [
70
+ "cursor",
71
+ "--label_cursor",
72
+ "--checkbox_cursor",
73
+ "--tag_cursor",
74
+ "--button_cursor",
75
+ "--textboxicon_icon_cursor",
76
+ ],
77
+ "values": {
78
+ "^default$": "var(--zdr-cursor-default)",
79
+ "^pointer$": "var(--zdr-cursor-pointer)",
80
+ "^text$": "var(--zdr-cursor-text)",
81
+ "^move$": "var(--zdr-cursor-move)",
82
+ }
83
+ }
84
+ ]
85
+ }
86
+
87
+ - Here we have added `^` before and `$` after default, pointer, text and move. Only if the exact words default, pointer, text and move are used, the values will be converted.
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getReactPreset;
7
+
8
+ function getReactPresetOptions() {
9
+ return {
10
+ runtime: 'classic',
11
+ // change it to 'automatic', when react version updated to 18.
12
+ useSpread: true
13
+ };
14
+ }
15
+
16
+ function getReactPreset({
17
+ disableES5Transpile
18
+ }) {
19
+ const reactPreset = require.resolve('@babel/preset-react');
20
+
21
+ return disableES5Transpile ? [reactPreset, getReactPresetOptions()] : reactPreset;
22
+ }
@@ -7,18 +7,47 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("../utils");
9
9
 
10
- let {
10
+ var _babelPresetReactOption = _interopRequireDefault(require("./babel-option-utils/babel-preset-react-option"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const {
11
15
  module: {
12
16
  mode
13
- }
17
+ },
18
+ babelCustomizationForLibrary: {
19
+ babelPlugins
20
+ },
21
+ enableTypeScript,
22
+ alias
14
23
  } = (0, _utils.getOptions)();
15
- let isProd = mode.toLowerCase() === 'prod';
24
+ const isProd = mode.toLowerCase() === 'prod';
25
+ const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
26
+ __DOCS__: false
27
+ } : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
28
+ "root": ["./"],
29
+ alias
30
+ }]];
31
+ const resolvedPlugins = [];
32
+ babelPlugins.forEach(plugin => {
33
+ if (Array.isArray(plugin)) {
34
+ resolvedPlugins.push([require.resolve(plugin[0]), plugin[1]]);
35
+ } else {
36
+ resolvedPlugins.push(require.resolve(plugin));
37
+ }
38
+ });
39
+ const plugins = [...defaultPlugins, ...resolvedPlugins];
40
+ const presets = [require.resolve('@babel/preset-env'), (0, _babelPresetReactOption.default)({
41
+ disableES5Transpile: false
42
+ })];
43
+
44
+ if (enableTypeScript) {
45
+ presets.push(require.resolve('@babel/preset-typescript'));
46
+ }
16
47
 
17
48
  var _default = () => ({
18
- presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')],
19
- plugins: [[require.resolve('babel-plugin-transform-define'), isProd ? {
20
- __DOCS__: false
21
- } : {}]]
49
+ presets: presets,
50
+ plugins: plugins
22
51
  });
23
52
 
24
53
  exports.default = _default;
@@ -7,28 +7,57 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("../utils");
9
9
 
10
- let {
10
+ var _babelPresetReactOption = _interopRequireDefault(require("./babel-option-utils/babel-preset-react-option"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const {
11
15
  module: {
12
16
  mode,
13
17
  disableES5Transpile
14
- }
18
+ },
19
+ babelCustomizationForLibrary: {
20
+ babelPlugins
21
+ },
22
+ enableTypeScript,
23
+ alias
15
24
  } = (0, _utils.getOptions)();
16
- let isProd = mode.toLowerCase() === 'prod';
25
+ const isProd = mode.toLowerCase() === 'prod';
26
+ const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
27
+ __DOCS__: false
28
+ } : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
29
+ 'root': ['./'],
30
+ alias
31
+ }]];
32
+ const resolvedPlugins = [];
33
+ babelPlugins.forEach(plugin => {
34
+ if (Array.isArray(plugin)) {
35
+ resolvedPlugins.push([require.resolve(plugin[0]), plugin[1]]);
36
+ } else {
37
+ resolvedPlugins.push(require.resolve(plugin));
38
+ }
39
+ });
40
+ const plugins = [...defaultPlugins, ...resolvedPlugins];
41
+ const presets = [[require.resolve('@babel/preset-env'), disableES5Transpile ? {
42
+ modules: false,
43
+ useBuiltIns: 'usage',
44
+ corejs: 3,
45
+ targets: {
46
+ browsers: ['last 3 Chrome versions', 'last 3 Firefox versions', 'last 3 Edge versions', 'last 3 Safari versions']
47
+ }
48
+ } : {
49
+ modules: false
50
+ }], (0, _babelPresetReactOption.default)({
51
+ disableES5Transpile
52
+ })];
53
+
54
+ if (enableTypeScript) {
55
+ presets.push(require.resolve('@babel/preset-typescript'));
56
+ }
17
57
 
18
58
  var _default = () => ({
19
- presets: [[require.resolve('@babel/preset-env'), disableES5Transpile ? {
20
- modules: false,
21
- useBuiltIns: 'usage',
22
- corejs: 3,
23
- targets: {
24
- browsers: ['last 3 Chrome versions', 'last 3 Firefox versions', 'last 3 Edge versions', 'last 3 Safari versions']
25
- }
26
- } : {
27
- modules: false
28
- }], require.resolve('@babel/preset-react')],
29
- plugins: [[require.resolve('babel-plugin-transform-define'), isProd ? {
30
- __DOCS__: false
31
- } : {}], require.resolve('@babel/plugin-syntax-dynamic-import')]
59
+ presets: presets,
60
+ plugins: plugins
32
61
  });
33
62
 
34
63
  exports.default = _default;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.runPreProcess = runPreProcess;
7
+
8
+ var _path = _interopRequireWildcard(require("path"));
9
+
10
+ var _fs = require("fs");
11
+
12
+ var _child_process = require("child_process");
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ function runPreProcess({
19
+ options,
20
+ option,
21
+ nodemon,
22
+ spawnSync
23
+ }) {
24
+ const {
25
+ preprocess
26
+ } = options;
27
+ const preprocessorPath = preprocess.runner ? _path.default.join(process.cwd(), preprocess.runner) : '';
28
+ const preprocessCli = preprocess.stopNodemon ? 'node' : nodemon;
29
+
30
+ if (preprocessorPath && (0, _fs.existsSync)(preprocessorPath)) {
31
+ const preprocessorDirPath = (0, _path.dirname)(preprocessorPath);
32
+ const watchOptions = preprocessCli === nodemon ? ['--watch', preprocessorDirPath] : []; // eslint-disable-next-line default-case
33
+
34
+ switch (option) {
35
+ case 'start':
36
+ case 'docs':
37
+ (0, _child_process.spawn)(preprocessCli, [preprocessorPath, ...watchOptions], {
38
+ stdio: 'inherit',
39
+ cwd: preprocessorDirPath
40
+ }); // NOTE: it's ok if we not close this here
41
+ // Because when node server stops this program will be closed So this nodemon will be killed as well
42
+
43
+ break;
44
+
45
+ case 'nowatchstart':
46
+ case 'devbuild':
47
+ case 'build:library:es':
48
+ case 'build:component:es':
49
+ case 'build:library:cmjs':
50
+ case 'build:component:cmjs':
51
+ spawnSync('node', [preprocessorPath], {
52
+ stdio: 'inherit',
53
+ cwd: preprocessorPath.slice(0, preprocessorPath.lastIndexOf('/') + 1)
54
+ });
55
+ break;
56
+
57
+ case 'preprocessor':
58
+ {
59
+ const result = spawnSync(preprocessCli, [preprocessorPath, ...watchOptions], {
60
+ stdio: 'inherit',
61
+ cwd: preprocessorDirPath
62
+ });
63
+ process.exit(result.status);
64
+ break;
65
+ }
66
+ }
67
+ } else if (option === 'preprocess') {
68
+ console.error(`preProcessor not exists ${preprocessorPath}`);
69
+ process.exit(0);
70
+ }
71
+ }
@@ -15,35 +15,53 @@ var _testPattern = require("./testPattern");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- let isWindows = _os.default.platform().toLowerCase() === 'win32';
19
- let ps = _path.default.sep;
20
- let options = (0, _utils.getOptions)();
21
- let {
18
+ const isWindows = _os.default.platform().toLowerCase() === 'win32';
19
+ const ps = _path.default.sep;
20
+ const options = (0, _utils.getOptions)();
21
+ const {
22
22
  app: {
23
23
  vendorExclude,
24
24
  customChunks,
25
- vendorInclude
25
+ vendorInclude,
26
+ customChunksBaseConfig
26
27
  }
27
28
  } = options;
29
+ const reactBundleIncludeList = ['react', 'react-dom', 'react-redux', 'react-transition-group', 'scheduler', 'prop-types'];
30
+ const vendorExcludeList = ['script-loader', 'raw-loader', ...reactBundleIncludeList, ...vendorExclude.map(vendorPath => vendorPath.replace(/[/\\]/g, _path.default.sep))];
31
+ const vendorIncludeList = [...vendorInclude].map(vendorPath => vendorPath.replace(/[/\\]/g, _path.default.sep));
28
32
 
29
- let isVendor = function isVendor(module) {
30
- let {
33
+ const isVendor = function isVendor(module) {
34
+ const {
31
35
  userRequest
32
36
  } = module;
33
- let excludeList = ['script-loader', 'raw-loader', 'react', 'react-dom'];
34
- excludeList = [...excludeList, ...vendorExclude];
35
- return userRequest && (vendorInclude.some(item => userRequest.indexOf(item) !== -1) || userRequest.indexOf('node_modules') >= 0 && userRequest.endsWith('.css') === false && userRequest.endsWith('publicPathConfig.js') === false && excludeList.every(item => userRequest.indexOf(`node_modules${ps}${item}${ps}`) === -1));
37
+ return userRequest && (vendorIncludeList.some(item => userRequest.indexOf(item) !== -1) || userRequest.indexOf('node_modules') >= 0 && userRequest.endsWith('.css') === false && userRequest.endsWith('publicPathConfig.js') === false && vendorExcludeList.every(item => userRequest.indexOf(`node_modules${ps}${item}${ps}`) === -1));
36
38
  };
37
39
 
38
- let isReact = module => {
39
- let {
40
+ const isReact = module => {
41
+ const {
40
42
  userRequest
41
43
  } = module;
42
- let reactBundle = ['react', 'react-dom'];
43
- return userRequest && reactBundle.some(pkg => userRequest.indexOf(`node_modules${ps}${pkg}${ps}`) >= 0);
44
+ return userRequest && reactBundleIncludeList.some(pkg => userRequest.indexOf(`node_modules${ps}${pkg}${ps}`) >= 0);
44
45
  };
45
46
 
46
- let defaultChunks = {
47
+ function rulesMatcher(pattern) {
48
+ if (typeof pattern === 'function') {
49
+ return pattern;
50
+ }
51
+
52
+ if (Array.isArray(pattern)) {
53
+ return ({
54
+ userRequest
55
+ }) => (0, _testPattern.testPattern)(userRequest, pattern);
56
+ }
57
+
58
+ return new RegExp(isWindows ? pattern.replace(/\//g, '\\') : pattern);
59
+ }
60
+
61
+ const baseSplitChunkConfig = Object.assign({
62
+ minSize: 15000
63
+ }, customChunksBaseConfig);
64
+ const specificCacheGroupConfig = {
47
65
  'react.vendor': {
48
66
  name: 'react.vendor',
49
67
  chunks: 'all',
@@ -63,45 +81,35 @@ let defaultChunks = {
63
81
  priority: -10
64
82
  }
65
83
  };
66
- let customChunksConfig = {};
84
+ const customChunksConfig = {};
67
85
  customChunks.map((obj, index) => ({
68
86
  name: obj.name,
69
- pattern: obj.pattern,
87
+ chunks: obj.chunks || 'all',
70
88
  minChunks: obj.minChunks || obj.size || 2,
71
- rules: obj.rules,
72
- // includeDepenency: obj.includeDepenency || false,
89
+ pattern: obj.pattern,
73
90
  priority: obj.priority || -10 * (index + 2),
74
- enforce: obj.enforce || true,
75
- maxSize: obj.maxSize,
76
- // || 0,
91
+ enforce: obj.enforce,
77
92
  minSize: obj.minSize,
78
93
  // || 20000,
79
- chunks: obj.chunks || 'all'
80
- })).map(({
94
+ maxSize: obj.maxSize,
95
+ // || 0,
96
+ reuseExistingChunk: obj.reuseExistingChunk,
97
+ cacheGroupName: obj.cacheGroupName || obj.name
98
+ })).forEach(({
81
99
  name,
82
- pattern,
100
+ chunks = 'all',
83
101
  minChunks,
84
- rules,
102
+ pattern,
85
103
  priority,
86
- // includeDepenency,
87
104
  enforce,
88
105
  minSize,
89
106
  maxSize,
90
- chunks = 'all'
107
+ reuseExistingChunk,
108
+ cacheGroupName
91
109
  }) => {
92
- let obj = {
93
- name,
94
- test: rules ? m => {
95
- const {
96
- userRequest
97
- } = m;
98
- return (0, _testPattern.testPattern)(userRequest, rules); // return (
99
- // pkgs.some(p => isRelated(userRequest, p)) ||
100
- // (includeDepenency && isDependency(m, pkgs))
101
- // );
102
- } : new RegExp(isWindows ? pattern.replace(/\//g, '\\') : pattern),
110
+ const obj = {
111
+ test: rulesMatcher(pattern),
103
112
  chunks,
104
- enforce,
105
113
  minChunks,
106
114
  priority
107
115
  };
@@ -114,13 +122,25 @@ customChunks.map((obj, index) => ({
114
122
  obj.maxSize = maxSize;
115
123
  }
116
124
 
117
- return customChunksConfig[name] = obj;
125
+ if (enforce !== false) {
126
+ obj.enforce = true;
127
+ }
128
+
129
+ if (name !== undefined) {
130
+ obj.name = name;
131
+ }
132
+
133
+ if (reuseExistingChunk !== undefined) {
134
+ obj.reuseExistingChunk = reuseExistingChunk;
135
+ }
136
+
137
+ customChunksConfig[cacheGroupName] = obj;
118
138
  });
119
- var _default = {
120
- minSize: 12000,
139
+ const splitChunkConfig = Object.assign({}, baseSplitChunkConfig, {
121
140
  cacheGroups: Object.assign({
122
141
  default: false,
123
142
  vendors: false
124
- }, defaultChunks, customChunksConfig)
125
- };
143
+ }, specificCacheGroupConfig, customChunksConfig)
144
+ });
145
+ var _default = splitChunkConfig;
126
146
  exports.default = _default;
@@ -13,25 +13,25 @@ var _path = require("path");
13
13
  const isWindows = _path.sep !== '/'; // this function will return true if pattern matched
14
14
 
15
15
  function _testPattern(req, pattern) {
16
- let modifyedPattern = pattern;
16
+ let modifiedPattern = pattern;
17
17
 
18
- if (/[*.$^]/.test(modifyedPattern)) {
18
+ if (/[*.$^]/.test(modifiedPattern)) {
19
19
  if (isWindows) {
20
- // modifyedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
21
- modifyedPattern = modifyedPattern.replace(/\//g, '\\\\');
20
+ // modifiedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
21
+ modifiedPattern = modifiedPattern.replace(/\//g, '\\\\');
22
22
  }
23
23
 
24
- modifyedPattern = modifyedPattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
25
- const re = new RegExp(modifyedPattern);
24
+ modifiedPattern = modifiedPattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
25
+ const re = new RegExp(modifiedPattern);
26
26
  return re.test(req);
27
27
  }
28
28
 
29
29
  if (isWindows) {
30
- // modifyedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
31
- modifyedPattern = modifyedPattern.replace(/\//g, '\\');
30
+ // modifiedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
31
+ modifiedPattern = modifiedPattern.replace(/\//g, '\\');
32
32
  }
33
33
 
34
- return req.indexOf(modifyedPattern) !== -1;
34
+ return req.indexOf(modifiedPattern) !== -1;
35
35
  }
36
36
 
37
37
  function testPattern(req, pattern) {