@zohodesk/react-cli 1.1.5-exp.3 → 1.1.5-exp.5

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -44,8 +44,15 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.1.5-exp.5
48
+ - fixed the issues regarding custom chunks base config schema.
49
+
50
+ # 1.1.5-exp.4
51
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
52
+
47
53
  # 1.1.5-exp.3
48
- - efficient chunk split related features update
54
+ - added options to split chunks base config
55
+ - added support for passing custom chunks split logic as function.
49
56
 
50
57
  **Issue Fix**
51
58
 
@@ -4,7 +4,7 @@ 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` **{ String | Function }** regex pattern as string and
7
+ - `pattern` **{ String | Function }** regex pattern as string and custom logic to split chunks can be defined using function
8
8
  - `name` **{ String }** chunk name
9
9
  - `size` **{ Number }** is count which is minimum chunk duplicated or need in chunks
10
10
 
@@ -59,7 +59,7 @@ function rulesMatcher(pattern) {
59
59
  }
60
60
 
61
61
  const baseSplitChunkConfig = Object.assign({
62
- minSize: 12000
62
+ minSize: 15000
63
63
  }, customChunksBaseConfig);
64
64
  const specificCacheGroupConfig = {
65
65
  'react.vendor': {
@@ -125,11 +125,11 @@ customChunks.map((obj, index) => ({
125
125
  obj.maxSize = maxSize;
126
126
  }
127
127
 
128
- if (name) {
128
+ if (name !== undefined) {
129
129
  obj.name = name;
130
130
  }
131
131
 
132
- if (reuseExistingChunk) {
132
+ if (reuseExistingChunk !== undefined) {
133
133
  obj.reuseExistingChunk = reuseExistingChunk;
134
134
  }
135
135
 
@@ -19,7 +19,7 @@ class ResourceHintsPlugin {
19
19
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk, hash) => {
20
20
  const idNameMap = chunk.getChunkMaps().name;
21
21
  const nameIdMap = {};
22
- let needsMap = false;
22
+ let needsMap = true;
23
23
 
24
24
  for (const key in idNameMap) {
25
25
  if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
@@ -32,7 +32,9 @@ class ResourceHintsPlugin {
32
32
  }
33
33
  }
34
34
 
35
- return Template.asString([source, '', `${mainTemplate.requireFn}.getChunkId = function getChunkId(chunkId) {`, Template.indent((needsMap ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`] : []).concat(['return chunkId;'])), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, `${mainTemplate.requireFn}.e(chunkId);`]), '};',
35
+ return Template.asString([source, '', `${mainTemplate.requireFn}.getChunkIds = function getChunkIds(chunkId) {`, Template.indent((needsMap ? [`const nameToChunkIdMap = ${JSON.stringify(nameIdMap)}`, 'const chunkNames = Object.keys(nameToChunkIdMap)'] : []).concat(['return chunkNames.filter(chunkName => chunkId.test(chunkName)).map(chunkName => nameToChunkIdMap[chunkName]);'])), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`let chunkIds = ${mainTemplate.requireFn}.getChunkIds(new RegExp(chunkId, 'i'))`, `chunkIds.forEach(idOfAChunk => {
36
+ ${mainTemplate.requireFn}.e(idOfAChunk);
37
+ })`]), '};',
36
38
  /*
37
39
  (needsMap
38
40
  ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
@@ -53,7 +55,7 @@ class ResourceHintsPlugin {
53
55
  ),
54
56
  '}',
55
57
  */
56
- `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, 'if(installedChunks[chunkId] === undefined) {', Template.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'document.head.appendChild(link);', `${mainTemplate.requireFn}.e(chunkId);` // 'var head = document.getElementsByTagName(\'head\')[0];',
58
+ `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkIds(new RegExp('^' + chunkId + '$'))[0]`, 'if(installedChunks[chunkId] === undefined) {', Template.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'document.head.appendChild(link);', `${mainTemplate.requireFn}.e(chunkId);` // 'var head = document.getElementsByTagName(\'head\')[0];',
57
59
  // mainTemplate.hooks.jsonpScript.call('', chunk, hash),
58
60
  // 'head.appendChild(script);'
59
61
  ]), '}']), '};']);
@@ -333,7 +333,7 @@ var _default = {
333
333
  inject: true
334
334
  },
335
335
  removePropTypes: false,
336
- customChunksBaseConfig: {},
336
+ customChunksBaseConfig: null,
337
337
  customChunks: [{
338
338
  name: 'styles',
339
339
  pattern: '\\.css$'