@zohodesk/react-cli 1.1.5-exp.3 → 1.1.5-exp.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/README.md +5 -1
- package/docs/CustomChunks.md +1 -1
- package/lib/plugins/ResourceHintsPlugin.js +5 -3
- package/npm-shrinkwrap.json +18996 -15
- package/package.json +1 -1
package/README.md
CHANGED
@@ -44,8 +44,12 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.1.5-exp.4
|
48
|
+
- added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
|
49
|
+
|
47
50
|
# 1.1.5-exp.3
|
48
|
-
-
|
51
|
+
- added options to split chunks base config
|
52
|
+
- added support for passing custom chunks split logic as function.
|
49
53
|
|
50
54
|
**Issue Fix**
|
51
55
|
|
package/docs/CustomChunks.md
CHANGED
@@ -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
|
|
@@ -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 =
|
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}.
|
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}.
|
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
|
]), '}']), '};']);
|