@zohodesk/react-cli 1.1.11-exp.1 → 1.1.11-exp.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +6 -0
- package/lib/pluginUtils/getProdPlugins.js +11 -4
- package/lib/plugins/StatsPlugin.js +146 -16
- package/lib/schemas/index.js +3 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -44,6 +44,12 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.1.11-exp.2 (11-8-2023)
|
48
|
+
|
49
|
+
**Changes**
|
50
|
+
- Added more customization support for `stats.json` output.
|
51
|
+
- Disabling `bundle-analyser` stats report for our customized stats output based on a flag.
|
52
|
+
|
47
53
|
# 1.1.11-exp.1 (8-8-2023)
|
48
54
|
|
49
55
|
**Changes**
|
@@ -91,7 +91,10 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
91
91
|
localeAttr: efcLocaleAttr
|
92
92
|
} = options.efc;
|
93
93
|
const {
|
94
|
-
enable: enableStats
|
94
|
+
enable: enableStats,
|
95
|
+
options: statsOptions,
|
96
|
+
excludeKeys: statsOutputExcludeKeys,
|
97
|
+
fileName: statsFileName
|
95
98
|
} = options.stats;
|
96
99
|
const hasEFC = newOptionForEnableEFC || prevOptionForEnableEFC;
|
97
100
|
const hashTempalate = enableChunkHash ? '.[chunkhash:20]_' : '';
|
@@ -232,9 +235,9 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
232
235
|
if (bundleAnalyze) {
|
233
236
|
pluginsArr.push(new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
|
234
237
|
analyzerMode: 'static',
|
235
|
-
generateStatsFile:
|
238
|
+
generateStatsFile: !enableStats,
|
236
239
|
openAnalyzer: false,
|
237
|
-
statsOptions: {
|
240
|
+
statsOptions: enableStats ? null : {
|
238
241
|
source: false,
|
239
242
|
normal: true,
|
240
243
|
chunks: false,
|
@@ -293,7 +296,11 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
293
296
|
|
294
297
|
|
295
298
|
customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
|
296
|
-
enableStats && new _StatsPlugin.default(
|
299
|
+
enableStats && pluginsArr.push(new _StatsPlugin.default({
|
300
|
+
statsOptions,
|
301
|
+
statsOutputExcludeKeys,
|
302
|
+
statsFileName
|
303
|
+
}));
|
297
304
|
return pluginsArr;
|
298
305
|
};
|
299
306
|
|
@@ -1,24 +1,40 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const {
|
4
|
-
defaulter
|
5
|
-
} = require('../utils/getOptions');
|
6
|
-
|
7
3
|
const fs = require('fs');
|
8
4
|
|
9
5
|
const path = require('path');
|
10
6
|
|
7
|
+
const {
|
8
|
+
Readable
|
9
|
+
} = require('stream');
|
10
|
+
|
11
11
|
const pluginName = 'stats-plugin';
|
12
12
|
const statsSchema = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
all: false,
|
14
|
+
children: false,
|
15
|
+
source: false,
|
16
|
+
assets: true,
|
17
|
+
chunks: true,
|
18
|
+
chunkGroups: true,
|
19
|
+
chunkOrigins: true,
|
20
|
+
chunkModules: true,
|
21
|
+
entrypoints: true,
|
22
|
+
modules: true,
|
23
|
+
moduleTrace: true,
|
24
|
+
outputPath: true,
|
25
|
+
performance: true,
|
26
|
+
reasons: true
|
18
27
|
};
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
|
29
|
+
class StatsPlugin {
|
30
|
+
constructor({
|
31
|
+
statsOptions = {},
|
32
|
+
statsOutputExcludeKeys = [],
|
33
|
+
statsFileName = 'stats.json'
|
34
|
+
}) {
|
35
|
+
this.excludeKeysInStat = statsOutputExcludeKeys;
|
36
|
+
this.statsOptions = Object.assign({}, statsSchema, statsOptions);
|
37
|
+
this.statsFileName = statsFileName;
|
22
38
|
}
|
23
39
|
|
24
40
|
apply(compiler) {
|
@@ -28,17 +44,131 @@ module.exports = class StatsPlugin {
|
|
28
44
|
});
|
29
45
|
}
|
30
46
|
|
47
|
+
transform(statsJson) {
|
48
|
+
return Object.keys(statsJson).reduce((acc, cur) => {
|
49
|
+
if (this.excludeKeysInStat.includes(cur)) {
|
50
|
+
return acc;
|
51
|
+
}
|
52
|
+
|
53
|
+
acc[cur] = statsJson[cur];
|
54
|
+
return acc;
|
55
|
+
}, {});
|
56
|
+
}
|
57
|
+
|
31
58
|
emitStats(statsJson) {
|
32
59
|
const {
|
33
60
|
outputPath
|
34
61
|
} = statsJson;
|
35
|
-
const
|
36
|
-
const
|
37
|
-
fs.writeFile(path.join(outputPath,
|
62
|
+
const transformedStatsJson = this.transform(statsJson);
|
63
|
+
const stringifiedJson = typeof statsJson === 'object' ? JSON.stringify(transformedStatsJson) : transformedStatsJson;
|
64
|
+
fs.writeFile(path.join(outputPath, this.statsFileName), stringifiedJson, err => {
|
38
65
|
if (err) {
|
39
66
|
throw err;
|
40
67
|
}
|
41
68
|
});
|
42
69
|
}
|
43
70
|
|
44
|
-
}
|
71
|
+
} // class StatsSerializeStream extends Readable {
|
72
|
+
// constructor(stats) {
|
73
|
+
// super();
|
74
|
+
// this._indentLevel = 0;
|
75
|
+
// this._stringifier = this._stringify(stats);
|
76
|
+
// }
|
77
|
+
// get _indent() {
|
78
|
+
// return ' '.repeat(this._indentLevel);
|
79
|
+
// }
|
80
|
+
// _read() {
|
81
|
+
// let readMore = true;
|
82
|
+
// while (readMore) {
|
83
|
+
// const { value, done } = this._stringifier.next();
|
84
|
+
// if (done) {
|
85
|
+
// this.push(null);
|
86
|
+
// readMore = false;
|
87
|
+
// } else {
|
88
|
+
// readMore = this.push(value);
|
89
|
+
// }
|
90
|
+
// }
|
91
|
+
// }
|
92
|
+
// *_stringify(obj) {
|
93
|
+
// if (
|
94
|
+
// typeof obj === 'string' ||
|
95
|
+
// typeof obj === 'number' ||
|
96
|
+
// typeof obj === 'boolean' ||
|
97
|
+
// obj === null
|
98
|
+
// ) {
|
99
|
+
// yield JSON.stringify(obj);
|
100
|
+
// } else if (Array.isArray(obj)) {
|
101
|
+
// yield '[';
|
102
|
+
// this._indentLevel++;
|
103
|
+
// let isFirst = true;
|
104
|
+
// for (let item of obj) {
|
105
|
+
// if (item === undefined) {
|
106
|
+
// item = null;
|
107
|
+
// }
|
108
|
+
// yield `${isFirst ? '' : ','}\n${this._indent}`;
|
109
|
+
// yield* this._stringify(item);
|
110
|
+
// isFirst = false;
|
111
|
+
// }
|
112
|
+
// this._indentLevel--;
|
113
|
+
// yield obj.length ? `\n${this._indent}]` : ']';
|
114
|
+
// } else {
|
115
|
+
// yield '{';
|
116
|
+
// this._indentLevel++;
|
117
|
+
// let isFirst = true;
|
118
|
+
// const entries = Object.entries(obj);
|
119
|
+
// for (const [itemKey, itemValue] of entries) {
|
120
|
+
// if (itemValue === undefined) {
|
121
|
+
// continue;
|
122
|
+
// }
|
123
|
+
// yield `${isFirst ? '' : ','}\n${this._indent}${JSON.stringify(
|
124
|
+
// itemKey
|
125
|
+
// )}: `;
|
126
|
+
// yield* this._stringify(itemValue);
|
127
|
+
// isFirst = false;
|
128
|
+
// }
|
129
|
+
// this._indentLevel--;
|
130
|
+
// yield entries.length ? `\n${this._indent}}` : '}';
|
131
|
+
// }
|
132
|
+
// }
|
133
|
+
// }
|
134
|
+
// function writeStats(stats, filepath) {
|
135
|
+
// return new Promise((resolve, reject) => {
|
136
|
+
// new StatsSerializeStream(stats)
|
137
|
+
// .on('end', resolve)
|
138
|
+
// .on('error', reject)
|
139
|
+
// .pipe(fs.createWriteStream(filepath));
|
140
|
+
// });
|
141
|
+
// }
|
142
|
+
// class StatsStremPlugin {
|
143
|
+
// constructor({ statsOptions = {}, statsOutputExcludeKeys = [] }) {
|
144
|
+
// this.excludeKeysInStat = statsOutputExcludeKeys;
|
145
|
+
// this.statsOptions = Object.assign({}, statsSchema, statsOptions);
|
146
|
+
// }
|
147
|
+
// apply(compiler) {
|
148
|
+
// compiler.hooks.done.tap(pluginName, stats => {
|
149
|
+
// const statsJson = stats.toJson(this.statsOptions);
|
150
|
+
// this.emitStats(statsJson);
|
151
|
+
// });
|
152
|
+
// }
|
153
|
+
// transform(statsJson) {
|
154
|
+
// return Object.keys(statsJson).reduce((acc, cur) => {
|
155
|
+
// if (this.excludeKeysInStat.includes(cur)) {
|
156
|
+
// return acc;
|
157
|
+
// }
|
158
|
+
// acc[cur] = statsJson[cur];
|
159
|
+
// return acc;
|
160
|
+
// }, {});
|
161
|
+
// }
|
162
|
+
// emitStats(statsJson) {
|
163
|
+
// const { outputPath } = statsJson;
|
164
|
+
// const transformedStatsJson = this.transform(statsJson);
|
165
|
+
// // const stringifiedJson =
|
166
|
+
// // typeof statsJson === 'object'
|
167
|
+
// // ? JSON.stringify(transformedStatsJson)
|
168
|
+
// // : transformedStatsJson;
|
169
|
+
// writeStats(transformedStatsJson, outputPath + 'jos-stats.json');
|
170
|
+
// }
|
171
|
+
// }
|
172
|
+
|
173
|
+
|
174
|
+
module.exports = StatsPlugin;
|
package/lib/schemas/index.js
CHANGED
package/npm-shrinkwrap.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zohodesk/react-cli",
|
3
|
-
"version": "1.1.11-exp.
|
3
|
+
"version": "1.1.11-exp.2",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "@zohodesk/react-cli",
|
9
|
-
"version": "1.1.11-exp.
|
9
|
+
"version": "1.1.11-exp.2",
|
10
10
|
"license": "ISC",
|
11
11
|
"dependencies": {
|
12
12
|
"@babel/cli": "7.10.5",
|