1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
| import _ from 'lodash';
| import gzipSize from 'gzip-size';
|
| import Node from './Node';
|
| export default class Module extends Node {
|
| constructor(name, data, parent) {
| super(name, parent);
| this.data = data;
| }
|
| get src() {
| return this.data.parsedSrc;
| }
|
| set src(value) {
| this.data.parsedSrc = value;
| delete this._gzipSize;
| }
|
| get size() {
| return this.data.size;
| }
|
| set size(value) {
| this.data.size = value;
| }
|
| get parsedSize() {
| return this.src ? this.src.length : undefined;
| }
|
| get gzipSize() {
| if (!_.has(this, '_gzipSize')) {
| this._gzipSize = this.src ? gzipSize.sync(this.src) : undefined;
| }
|
| return this._gzipSize;
| }
|
| mergeData(data) {
| if (data.size) {
| this.size += data.size;
| }
|
| if (data.parsedSrc) {
| this.src = (this.src || '') + data.parsedSrc;
| }
| }
|
| toChartData() {
| return {
| id: this.data.id,
| label: this.name,
| path: this.path,
| statSize: this.size,
| parsedSize: this.parsedSize,
| gzipSize: this.gzipSize
| };
| }
|
| };
|
|