-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
112 lines (100 loc) · 2.96 KB
/
bundle.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const fs = require('fs');
const path = require('path');
const { gzipSync } = require("zlib");
const brotli = require('iltorb');
const MemoryFS = require("memory-fs")
const webpack = require('webpack');
const makeWebpackConfig = require('package-build-stats/src/webpack.config');
const { decimal } = require('./framework');
// function createEntryPoint(name, installPath, customImports) {
// const entryPath = path.join(installPath, 'index.js')
// let importStatement;
// if (customImports) {
// importStatement = `
// import { ${customImports.join(', ')} } from '${name}';
// console.log(${customImports.join(', ')})
// `
// } else {
// importStatement = `const p = require('${name}'); console.log(p)`
// }
// try {
// fs.writeFileSync(
// entryPath,
// importStatement,
// "utf-8"
// )
// return entryPath
// } catch (err) {
// throw new CustomError("EntryPointError", err)
// }
const LANGS = [
['English', 'en'],
['Spanish', 'es'],
['French', 'fr'],
['German', 'de'],
['Italian', 'it'],
['Portiguese', 'pt'],
['Japanese', 'ja'],
['Korean', 'ko'],
['Chinese', 'zh']
];
const ENTRIES = {
'@phensley/cldr': {
entry: './cldr-engine/cldr.js',
resources: './node_modules/@phensley/cldr/packs'
},
'@phensley/cldr-core': {
entry: './cldr-engine/cldr-core.js',
resources: './packs'
}
};
const resources = root => {
for (const [name, lang] of LANGS) {
const p = path.join(root, `${lang}.json`);
const raw = fs.readFileSync(p);
const gz = gzipSync(raw);
const br = brotli.compressSync(raw);
console.log(`| ${name} resource pack | ${decimal(raw.length)} | ${decimal(gz.length)} | ${decimal(br.length)} |`);
}
};
Object.keys(ENTRIES).forEach(key => {
const compiler = webpack(makeWebpackConfig({
entryPoint: ENTRIES[key].entry,
externals: []
}));
const memoryFileSystem = new MemoryFS()
compiler.outputFileSystem = memoryFileSystem
compiler.run((err, stats) => {
const jsonStats = stats ? stats.toJson({
assets: true,
children: false,
chunks: false,
chunkGroups: false,
chunkModules: false,
chunkOrigins: false,
modules: true,
errorDetails: false,
entrypoints: false,
reasons: false,
maxModules: 500,
performance: false,
source: true,
depth: true,
providedExports: true,
warnings: false,
modulesSort: "depth",
}) : {}
const bundleName = 'main.bundle.js';
const bundle = path.join(process.cwd(), 'dist', bundleName);
const bundleContents = memoryFileSystem.readFileSync(bundle);
const size = jsonStats.assets
.filter(x => x.name === bundleName)
.pop()
.size
const gz = gzipSync(bundleContents);
const br = brotli.compressSync(bundleContents);
console.log(`| ${key} library | ${decimal(size)} | ${decimal(gz.length)} | ${decimal(br.length)} |`);
resources(ENTRIES[key].resources);
console.log('\n\n');
});
});