@zohodesk/react-cli 1.1.5-exp.2 → 1.1.5-exp.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -11
- package/docs/CustomChunks.md +6 -6
- package/lib/common/splitChunks.js +63 -40
- package/lib/common/testPattern.js +9 -9
- package/lib/schemas/index.js +1 -0
- package/lib/utils/getOptions.js +25 -7
- package/npm-shrinkwrap.json +15 -18996
- package/package.json +1 -1
package/README.md
CHANGED
@@ -44,12 +44,8 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
-
# 1.1.5-exp.
|
48
|
-
|
49
|
-
**Issue Fix**
|
50
|
-
- local install react-cli spawnSync Error fix in npm 8
|
51
|
-
|
52
|
-
# 1.1.5
|
47
|
+
# 1.1.5-exp.3
|
48
|
+
- efficient chunk split related features update
|
53
49
|
|
54
50
|
**Issue Fix**
|
55
51
|
|
@@ -62,11 +58,6 @@ Now to run app
|
|
62
58
|
- `0px` variable value conversion issue fixed
|
63
59
|
- pattern exclude for postcss plugins case fixed
|
64
60
|
|
65
|
-
# 1.1.3
|
66
|
-
|
67
|
-
**Issue Fix**
|
68
|
-
- local install react-cli spawnSync Error fix
|
69
|
-
|
70
61
|
# 1.1.2
|
71
62
|
|
72
63
|
**Issue Fix**
|
package/docs/CustomChunks.md
CHANGED
@@ -4,17 +4,17 @@ 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
|
7
|
+
- `pattern` **{ String | Function }** regex pattern as string and
|
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
|
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
|
@@ -23,4 +23,4 @@ for more details [SplitChunkPlugin](https://webpack.js.org/plugins/split-chunks-
|
|
23
23
|
- `enforce`: enforce default value is true,
|
24
24
|
- `maxSize`: maxSize, default value is 0,
|
25
25
|
- `minSize`: minSize, default value is 20000,
|
26
|
-
|
26
|
+
includeDependency: includeDependency default value is false
|
@@ -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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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 reactBundle = ['react', 'react-dom', 'react-redux', 'react-transition-group', 'scheduler', 'prop-types'];
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
const isVendor = function isVendor(module) {
|
32
|
+
const {
|
31
33
|
userRequest
|
32
34
|
} = module;
|
33
|
-
let excludeList = ['script-loader', 'raw-loader',
|
35
|
+
let excludeList = ['script-loader', 'raw-loader', ...reactBundle];
|
34
36
|
excludeList = [...excludeList, ...vendorExclude];
|
35
37
|
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));
|
36
38
|
};
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
const isReact = module => {
|
41
|
+
const {
|
40
42
|
userRequest
|
41
43
|
} = module;
|
42
|
-
let reactBundle = ['react', 'react-dom'];
|
43
44
|
return userRequest && reactBundle.some(pkg => userRequest.indexOf(`node_modules${ps}${pkg}${ps}`) >= 0);
|
44
45
|
};
|
45
46
|
|
46
|
-
|
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: 12000
|
63
|
+
}, customChunksBaseConfig);
|
64
|
+
const specificCacheGroupConfig = {
|
47
65
|
'react.vendor': {
|
48
66
|
name: 'react.vendor',
|
49
67
|
chunks: 'all',
|
@@ -63,43 +81,36 @@ let defaultChunks = {
|
|
63
81
|
priority: -10
|
64
82
|
}
|
65
83
|
};
|
66
|
-
|
84
|
+
const customChunksConfig = {};
|
67
85
|
customChunks.map((obj, index) => ({
|
68
86
|
name: obj.name,
|
69
|
-
|
87
|
+
chunks: obj.chunks || 'all',
|
70
88
|
minChunks: obj.minChunks || obj.size || 2,
|
71
|
-
|
72
|
-
// includeDepenency: obj.includeDepenency || false,
|
89
|
+
pattern: obj.pattern,
|
73
90
|
priority: obj.priority || -10 * (index + 2),
|
74
91
|
enforce: obj.enforce || true,
|
75
|
-
maxSize: obj.maxSize,
|
76
|
-
// || 0,
|
77
92
|
minSize: obj.minSize,
|
78
93
|
// || 20000,
|
79
|
-
|
80
|
-
|
94
|
+
maxSize: obj.maxSize,
|
95
|
+
// || 0,
|
96
|
+
reuseExistingChunk: obj.reuseExistingChunk || false,
|
97
|
+
automaticNamePrefix: obj.automaticNamePrefix || null,
|
98
|
+
cacheGroupName: obj.cacheGroupName || obj.name
|
99
|
+
})).forEach(({
|
81
100
|
name,
|
82
|
-
|
101
|
+
chunks = 'all',
|
83
102
|
minChunks,
|
84
|
-
|
103
|
+
pattern,
|
85
104
|
priority,
|
86
|
-
// includeDepenency,
|
87
105
|
enforce,
|
88
106
|
minSize,
|
89
107
|
maxSize,
|
90
|
-
|
108
|
+
reuseExistingChunk,
|
109
|
+
automaticNamePrefix,
|
110
|
+
cacheGroupName
|
91
111
|
}) => {
|
92
|
-
|
93
|
-
|
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),
|
112
|
+
const obj = {
|
113
|
+
test: rulesMatcher(pattern),
|
103
114
|
chunks,
|
104
115
|
enforce,
|
105
116
|
minChunks,
|
@@ -114,13 +125,25 @@ customChunks.map((obj, index) => ({
|
|
114
125
|
obj.maxSize = maxSize;
|
115
126
|
}
|
116
127
|
|
117
|
-
|
128
|
+
if (name) {
|
129
|
+
obj.name = name;
|
130
|
+
}
|
131
|
+
|
132
|
+
if (reuseExistingChunk) {
|
133
|
+
obj.reuseExistingChunk = reuseExistingChunk;
|
134
|
+
}
|
135
|
+
|
136
|
+
if (automaticNamePrefix) {
|
137
|
+
obj.automaticNamePrefix = automaticNamePrefix;
|
138
|
+
}
|
139
|
+
|
140
|
+
customChunksConfig[cacheGroupName] = obj;
|
118
141
|
});
|
119
|
-
|
120
|
-
minSize: 12000,
|
142
|
+
const splitChunkConfig = Object.assign({}, baseSplitChunkConfig, {
|
121
143
|
cacheGroups: Object.assign({
|
122
144
|
default: false,
|
123
145
|
vendors: false
|
124
|
-
},
|
125
|
-
};
|
146
|
+
}, specificCacheGroupConfig, customChunksConfig)
|
147
|
+
});
|
148
|
+
var _default = splitChunkConfig;
|
126
149
|
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
|
16
|
+
let modifiedPattern = pattern;
|
17
17
|
|
18
|
-
if (/[*.$^]/.test(
|
18
|
+
if (/[*.$^]/.test(modifiedPattern)) {
|
19
19
|
if (isWindows) {
|
20
|
-
//
|
21
|
-
|
20
|
+
// modifiedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
|
21
|
+
modifiedPattern = modifiedPattern.replace(/\//g, '\\\\');
|
22
22
|
}
|
23
23
|
|
24
|
-
|
25
|
-
const re = new RegExp(
|
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
|
-
//
|
31
|
-
|
30
|
+
// modifiedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
|
31
|
+
modifiedPattern = modifiedPattern.replace(/\//g, '\\');
|
32
32
|
}
|
33
33
|
|
34
|
-
return req.indexOf(
|
34
|
+
return req.indexOf(modifiedPattern) !== -1;
|
35
35
|
}
|
36
36
|
|
37
37
|
function testPattern(req, pattern) {
|
package/lib/schemas/index.js
CHANGED
package/lib/utils/getOptions.js
CHANGED
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _child_process = require("child_process");
|
9
9
|
|
10
|
-
var _fs =
|
10
|
+
var _fs = _interopRequireWildcard(require("fs"));
|
11
11
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
13
13
|
|
@@ -15,6 +15,10 @@ var _schemas = _interopRequireDefault(require("../schemas"));
|
|
15
15
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
17
|
|
18
|
+
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); }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
18
22
|
// import { argv } from 'process';
|
19
23
|
const args = process.argv.slice(2); // console.log('argv', argv);
|
20
24
|
|
@@ -183,8 +187,9 @@ function deprecationSupport(options) {
|
|
183
187
|
Object.keys(options.app.patterns).forEach(key => {
|
184
188
|
if (options.app.exclude[key] && options.app.patterns[key].length === 0) {
|
185
189
|
let tempArr = options.app.exclude[key];
|
186
|
-
tempArr = tempArr.map(
|
187
|
-
x =
|
190
|
+
tempArr = tempArr.map(_x => {
|
191
|
+
const x = _x.replace(/\//gi, _path.default.sep);
|
192
|
+
|
188
193
|
return `!**${x[0] === _path.default.sep || x[0] === '@' ? '' : _path.default.sep}${x}${x[x.length - 1] === _path.default.sep ? '' : _path.default.sep}**`;
|
189
194
|
});
|
190
195
|
options.app.patterns[key] = tempArr;
|
@@ -193,8 +198,9 @@ function deprecationSupport(options) {
|
|
193
198
|
Object.keys(options.docs.patterns).forEach(key => {
|
194
199
|
if (options.docs.exclude[key] && options.docs.patterns[key].length === 0) {
|
195
200
|
let tempArr = options.docs.exclude[key];
|
196
|
-
tempArr = tempArr.map(
|
197
|
-
x =
|
201
|
+
tempArr = tempArr.map(_x => {
|
202
|
+
const x = _x.replace(/\//gi, _path.default.sep);
|
203
|
+
|
198
204
|
return `!**${x[0] === _path.default.sep || x[0] === '@' ? '' : _path.default.sep}${x}${x[x.length - 1] === _path.default.sep ? '' : _path.default.sep}**`;
|
199
205
|
});
|
200
206
|
options.docs.patterns[key] = tempArr;
|
@@ -202,18 +208,30 @@ function deprecationSupport(options) {
|
|
202
208
|
});
|
203
209
|
}
|
204
210
|
|
211
|
+
const getOptionsFromConfigFile = (appPath, configFileName) => {
|
212
|
+
const fileName = configFileName || 'build.config.js';
|
213
|
+
|
214
|
+
const packagePath = _path.default.join(appPath, fileName);
|
215
|
+
|
216
|
+
if ((0, _fs.existsSync)(packagePath)) {
|
217
|
+
return require(packagePath).config;
|
218
|
+
}
|
219
|
+
|
220
|
+
return null;
|
221
|
+
};
|
222
|
+
|
205
223
|
const getOptions = () => {
|
206
224
|
if (global.reactCLIOptions) {
|
207
225
|
return global.reactCLIOptions;
|
208
226
|
}
|
209
227
|
|
210
228
|
const appPath = process.cwd();
|
211
|
-
let userSchemas;
|
229
|
+
let userSchemas = getOptionsFromConfigFile(appPath, processEnv.config_file);
|
212
230
|
|
213
231
|
const packagePath = _path.default.join(appPath, 'package.json');
|
214
232
|
|
215
233
|
if (_fs.default.existsSync(packagePath)) {
|
216
|
-
userSchemas = require(packagePath)['react-cli'] || {};
|
234
|
+
userSchemas = userSchemas || require(packagePath)['react-cli'] || {};
|
217
235
|
}
|
218
236
|
|
219
237
|
const options = defaulter(_schemas.default, userSchemas || {}); // for future may be for npm 8 edge cases
|