@zohodesk/react-cli 1.1.8 → 1.1.10

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.
@@ -0,0 +1,25 @@
1
+ {
2
+ "cSpell.words": [
3
+ "classname",
4
+ "cmjs",
5
+ "devbuild",
6
+ "escodegen",
7
+ "expublish",
8
+ "gitclone",
9
+ "hgclone",
10
+ "mockapi",
11
+ "mockserver",
12
+ "nowatchserver",
13
+ "nowatchstart",
14
+ "postpublish",
15
+ "propertytojson",
16
+ "sslcert",
17
+ "sslcertupdate",
18
+ "sstest",
19
+ "uglifycss",
20
+ "valuereplacer",
21
+ "xmlhttprequest",
22
+ "zohodesk",
23
+ "zsecurity"
24
+ ]
25
+ }
package/README.md CHANGED
@@ -44,27 +44,82 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.1.10 (2-8-2023)
48
+
49
+ **Issue Fix:**
50
+
51
+ - undefined plugin postcss issue fixed for docs.
52
+ - unnecessary deprecation warning stopped. (for exclude config)
53
+
54
+ # 1.1.9 (25-7-2023)
55
+
56
+ **Features:-**
57
+
58
+ - we have added config file support for react-cli schema. the default config file name `build.config.js` support added. In `build.config.js` you must export configuration object under `config` key. And Note: `build.config.js` is high priority then `package.json` `react-cli` config.
59
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
60
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
61
+ - added support for pattern as function for custom chunks split logic.
62
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
63
+ - added `postCssPluginOrder` feature :
64
+
65
+ - If `app > postCssPluginOrder` or `docs > postCssPluginOrder` is set to "false", default plugin order will be followed.
66
+ - If `app > postCssPluginOrder` or `docs > postCssPluginOrder` is set to "true", order preserved in `plugins` Object will be considered.
67
+ - If `app > postCssPluginOrder` or `docs > postCssPluginOrder` is set to an array with plugins in a custom order, the custom order will be considered.
68
+
69
+ - We use the same plugin names as in `patterns` for the plugins to execute successfully.
70
+
71
+ **Issue Fix**
72
+
73
+ - fixed file path separator issue with split chunks config for vendor exclude list for windows (that was work well for mac and ubuntu only issue in windows).
74
+ - fixed cssUniqueness pattern not working in docs.
75
+
76
+ **Changes**
77
+
78
+ - previously all custom chunks are enforce true, no we have given support for enforce false for chunks on splitChunks config.
79
+
47
80
  # 1.1.8
48
81
 
49
82
  **Issue Fix**
50
- - Docs fix for Selector Replace 'always require arguement' issue.
83
+
84
+ - Docs fix for Selector Replace 'always require argument' issue.
51
85
 
52
86
  # 1.1.7
53
87
 
54
88
  **Feature**
89
+
55
90
  - Markdown parser feature added in docs
56
- For more info please refer to :
57
- [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/MarkdownParser.md)
91
+ For more info please refer to :
92
+ [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/MarkdownParser.md)
93
+
94
+ # 1.1.6-exp.2
95
+
96
+ - fixed file path separator issue with split chunks config for vendor exclude list.
97
+ - added support for not doing enforce true for chunks on splitChunks config.
98
+
99
+ # 1.1.5-exp.5
100
+
101
+ - fixed the issues regarding custom chunks base config schema.
102
+
103
+ # 1.1.5-exp.4
104
+
105
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
106
+
107
+ # 1.1.5-exp.3
108
+
109
+ - added options to split chunks base config
110
+ - added support for passing custom chunks split logic as function.
58
111
 
59
112
  # 1.1.6
60
113
 
61
114
  **Issue Fix**
115
+
62
116
  - local install react-cli spawnSync Error fix in npm 8
63
117
  - babel version update issue fix (Cannot read properties of undefined (reading 'file')) and (BABEL_TRANSFORM_ERROR)
64
118
 
65
119
  # 1.1.5-exp.2
66
120
 
67
121
  **Issue Fix**
122
+
68
123
  - local install react-cli spawnSync Error fix in npm 8
69
124
 
70
125
  # 1.1.5
@@ -76,6 +131,7 @@ For more info please refer to :
76
131
  # 1.1.4
77
132
 
78
133
  **Issue Fix**
134
+
79
135
  - global install react-cli spawnSync Error fix
80
136
  - `0px` variable value conversion issue fixed
81
137
  - pattern exclude for postcss plugins case fixed
@@ -83,6 +139,7 @@ For more info please refer to :
83
139
  # 1.1.3
84
140
 
85
141
  **Issue Fix**
142
+
86
143
  - local install react-cli spawnSync Error fix
87
144
 
88
145
  # 1.1.2
@@ -94,54 +151,63 @@ For more info please refer to :
94
151
  # 1.1.1
95
152
 
96
153
  **Issue Fix**
154
+
97
155
  - docs component name incorrect in windows, when using --enableReactLive issue fixed.
98
156
 
99
- **Feature Update**
157
+ **Feature Update**
158
+
100
159
  - Support for desk-library to use Selector Replace plugin using individual script. To use `react-cli selectorReplacer [source] [target]`
101
160
 
102
161
  # 1.1.0
103
162
 
104
163
  **Feature Update**
105
- - Support for desk-library to use variable convertion plugin using individual script. To use `react-cli variableConverter [source] [target]`
164
+
165
+ - Support for desk-library to use variable conversion plugin using individual script. To use `react-cli variableConverter [source] [target]`
106
166
  - pattern filter changes, new filter system instead of exclude to include or exclude files for plugins.
107
- For more info please refer to :
108
- [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/patternFiltering.md)
167
+ For more info please refer to :
168
+ [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/patternFiltering.md)
109
169
  - React Live feature implemented for Docs.
110
- [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/ReactLive.md)
170
+ [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/ReactLive.md)
111
171
 
112
172
  # 1.0.3-beta.1
113
173
 
114
174
  **Issue Fix**
115
- - nock api not working issue fixed. This error throwing in @zohodesk/react-cli@1.0.2 version. but working in older versions ( 0.0.1-beta.178 )
116
175
 
176
+ - nock api not working issue fixed. This error throwing in @zohodesk/react-cli@1.0.2 version. but working in older versions ( 0.0.1-beta.178 )
117
177
 
118
178
  # 1.0.3
119
179
 
120
180
  **Feature Update**
181
+
121
182
  - Support for global httpsCerts usage
122
183
  - Support for global client_packages_group usage
123
- - custom attribute for dynamically loading chunks, In this version we merged changes from [0.0.1-beta.167.1](#0.0.1-beta.167.1).
124
- **Package Update**
125
- - @zohodesk/client_packages_group@**1.0.1** ==> @zohodesk/client_packages_group@**1.0.2**
126
-
127
-
184
+ - custom attribute for dynamically loading chunks, In this version we merged changes from [0.0.1-beta.167.1](#0.0.1-beta.167.1).
185
+ **Package Update**
186
+ - @zohodesk/client_packages_group@**1.0.1** ==> @zohodesk/client_packages_group@**1.0.2**
128
187
 
129
188
  # 1.0.2
130
189
 
131
190
  **Feature Update**
191
+
132
192
  - Selector replace plugin made as a custom postcss-plugin with update to code that was unpublished in package.
133
193
 
134
194
  # 1.0.1
135
195
 
136
196
  **Issue Fix**
197
+
137
198
  - variable conversion for px and var(--) values in same declaration was not supported, now it is supported.
138
199
  - package-lock.json removed from `.npmignore`
139
200
 
140
201
  **Feature Update**
202
+
141
203
  - exclude added to Selector Plugin
204
+
142
205
  # 1.0.0
206
+
143
207
  ## Major Release
208
+
144
209
  **Changes:**
210
+
145
211
  - File support added for `.webp` for `docs`, `dev` and `prod` mode
146
212
  - File support added for `.webm` for `docs`, `dev` and `prod` mode
147
213
 
@@ -149,12 +215,11 @@ For more info please refer to :
149
215
 
150
216
  - We have remove ssl certificate for security reasons.
151
217
  So default https server won't run.
152
- In order to make it work as before you need to specify two things
218
+ In order to make it work as before you need to specify two things
153
219
  1. install `@zohodesk-private/client_dev_cert`
154
- 2. `react-cli.app.server.httpsCerts` option example `"httpsCerts": "@zohodesk-private/client_dev_cert"`
155
- unless configaration are proper this may break `start` , `docs` , `nowatchstart`. and mock wms `/wmsmockapi` won't work.
156
- So Please be carefull when you update this version or above without proper configaration.
157
-
220
+ 2. `react-cli.app.server.httpsCerts` option example `"httpsCerts": "@zohodesk-private/client_dev_cert"`
221
+ unless configaration are proper this may break `start` , `docs` , `nowatchstart`. and mock wms `/wmsmockapi` won't work.
222
+ So Please be carefull when you update this version or above without proper configaration.
158
223
 
159
224
  # 0.0.1-beta.178
160
225
 
@@ -167,11 +232,11 @@ For more info please refer to :
167
232
 
168
233
  - We have remove ssl certificate for security reasons.
169
234
  So default https server won't run.
170
- In order to make it work as before you need to specify two things
235
+ In order to make it work as before you need to specify two things
171
236
  1. install `@zohodesk-private/client_dev_cert`
172
- 2. `react-cli.app.server.httpsCerts` option example `"httpsCerts": "@zohodesk-private/client_dev_cert"`
173
- unless configaration are proper this may break `start` , `docs` , `nowatchstart`.
174
- So Please be carefull when you update this version or above without proper configaration.
237
+ 2. `react-cli.app.server.httpsCerts` option example `"httpsCerts": "@zohodesk-private/client_dev_cert"`
238
+ unless configaration are proper this may break `start` , `docs` , `nowatchstart`.
239
+ So Please be carefull when you update this version or above without proper configaration.
175
240
 
176
241
  # 0.0.1-exp.178.2
177
242
 
@@ -185,11 +250,11 @@ For more info please refer to :
185
250
 
186
251
  - We have remove ssl certificate for security reasons.
187
252
  So default https server won't run.
188
- In order to make it work as before you need to specify two things
253
+ In order to make it work as before you need to specify two things
189
254
  1. install `@zohodesk-private/client_dev_cert`
190
- 2. `react-cli.app.server.httpsCerts` option example `"httpsCerts": "@zohodesk-private/client_dev_cert"`
191
- unless configaration are proper this may break `start` , `docs` , `nowatchstart`.
192
- So Please be carefull when you update this version or above without proper configaration.
255
+ 2. `react-cli.app.server.httpsCerts` option example `"httpsCerts": "@zohodesk-private/client_dev_cert"`
256
+ unless configaration are proper this may break `start` , `docs` , `nowatchstart`.
257
+ So Please be carefull when you update this version or above without proper configaration.
193
258
 
194
259
  # 0.0.1-beta.177
195
260
 
@@ -347,8 +412,9 @@ Features:-
347
412
  - In docs we have added `Description` for Component Props- check out it in `PropTypes` tab
348
413
 
349
414
  # 0.0.1-beta.167.1
415
+
350
416
  In this version we merged changes from [0.0.1-betaa.138.1](#0.0.1-betaa.138.1).
351
- and with [0.0.1-beta.167](#0.0.1-beta.167) version changes.
417
+ and with [0.0.1-beta.167](#0.0.1-beta.167) version changes.
352
418
 
353
419
  # 0.0.1-beta.167
354
420
 
@@ -612,6 +678,7 @@ impact servise related changes:-
612
678
  - few enhancements
613
679
 
614
680
  # 0.0.1-betaa.138.1
681
+
615
682
  - new feature added for custom extra attribute for dynamically added tags by webpack.
616
683
  - To enable this feature you need to enable "react-cli" => "app" => "customAttributes" => "enable"
617
684
  - For more [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/9eea8df14e55584b2114b5e484ca8b751a4ba191/src/plugins/CustomAttributePlugin.md)
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('../src/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' }
@@ -477,8 +437,9 @@ switch (option) {
477
437
  case '--v':
478
438
  case '-v':
479
439
  log(`@zohodesk/react-cli v${require('../package.json').version}`);
440
+ log(`Node Js Version : ${process.version}`);
441
+ log(`Npm Version : ${execSync('npm --version')}`);
480
442
  break;
481
-
482
443
  default:
483
444
  log(`react-cli > Unknown option "${option}"`);
484
445
  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,66 @@
1
+ "use strict";
2
+
3
+ const path = require('path');
4
+
5
+ const {
6
+ existsSync
7
+ } = require('fs');
8
+
9
+ const {
10
+ spawn
11
+ } = require('child_process');
12
+
13
+ exports.runPreProcess = function runPreProcess({
14
+ options,
15
+ option,
16
+ nodemon,
17
+ spawnSync
18
+ }) {
19
+ const {
20
+ preprocess
21
+ } = options;
22
+ const preprocessorPath = preprocess.runner ? path.join(process.cwd(), preprocess.runner) : '';
23
+ const preprocessCli = preprocess.stopNodemon ? 'node' : nodemon;
24
+
25
+ if (preprocessorPath && existsSync(preprocessorPath)) {
26
+ const preprocessorDirPath = path.dirname(preprocessorPath);
27
+ const watchOptions = preprocessCli === nodemon ? ['--watch', preprocessorDirPath] : []; // eslint-disable-next-line default-case
28
+
29
+ switch (option) {
30
+ case 'start':
31
+ case 'docs':
32
+ spawn(preprocessCli, [preprocessorPath, ...watchOptions], {
33
+ stdio: 'inherit',
34
+ cwd: preprocessorDirPath
35
+ }); // NOTE: it's ok if we not close this here
36
+ // Because when node server stops this program will be closed So this nodemon will be killed as well
37
+
38
+ break;
39
+
40
+ case 'nowatchstart':
41
+ case 'devbuild':
42
+ case 'build:library:es':
43
+ case 'build:component:es':
44
+ case 'build:library:cmjs':
45
+ case 'build:component:cmjs':
46
+ spawnSync('node', [preprocessorPath], {
47
+ stdio: 'inherit',
48
+ cwd: preprocessorPath.slice(0, preprocessorPath.lastIndexOf('/') + 1)
49
+ });
50
+ break;
51
+
52
+ case 'preprocessor':
53
+ {
54
+ const result = spawnSync(preprocessCli, [preprocessorPath, ...watchOptions], {
55
+ stdio: 'inherit',
56
+ cwd: path.dirname(preprocessorPath)
57
+ });
58
+ process.exit(result.status);
59
+ break;
60
+ }
61
+ }
62
+ } else if (option === 'preprocess') {
63
+ console.error(`preProcessor not exists ${preprocessorPath}`);
64
+ process.exit(0);
65
+ }
66
+ };
@@ -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;