-
Notifications
You must be signed in to change notification settings - Fork 78
/
.size-limit.js
120 lines (108 loc) · 3.23 KB
/
.size-limit.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
113
114
115
116
117
118
119
120
const fs = require('fs');
const base = getOutputPath() + '/';
module.exports = [
{
name: 'initial',
path: base + '(main|styles|runtime|polyfills)*.js',
limit: '125Kb',
},
{
name: 'main',
path: base + 'main*',
limit: '120Kb',
},
{
name: 'styles',
path: base + 'styles*',
limit: '10Kb',
},
{
name: 'common',
path: base + 'common*',
limit: '10KB',
},
{
name: 'movie-detail-page',
path:
base +
'projects_movies_src_app_pages_movie-detail-page_movie-detail-page_module*',
limit: '10KB',
},
{
name: 'person-detail-page',
path:
base +
'projects_movies_src_app_pages_person-detail-page_person-detail-page_module*',
limit: '10KB',
},
];
function getOutputPath() {
const project = 'movies';
const target = 'build';
const arrayBuffer = fs.readFileSync('./angular.json');
const projects = JSON.parse(arrayBuffer).projects[project];
return projects.architect[target].options.outputPath;
}
function getOutputFiles() {
const project = 'movies';
const target = 'build';
const arrayBuffer = fs.readFileSync('./angular.json');
const projects = JSON.parse(arrayBuffer).projects[project];
const outputPath = projects.architect[target].options.outputPath;
return fs
.readdirSync(outputPath)
.filter((name) => name.endsWith('.js') || name.endsWith('.css'))
.map((f) => [f, outputPath + '/' + f]);
}
function useAngularConfig() {
/* Debugging/Future automation
const [projectCommand, project, targetCommand, target] = process.argv.slice(
-(process.argv.length - 2)
);
if (
!(projectCommand && projectCommand.split('-').join('') === 'project') ||
!(targetCommand && targetCommand.split('-').join('') === 'target')
) {
console.error(
'command: ',
[projectCommand, project, targetCommand, target].join(' '),
'is incorrect'
);
throw new Error('it has to be: --project <name> --target <name>');
return;
}
if (projectCommand.split('-').join('') === project) {
console.log('command: ', projectCommand, 'has to be --project');
}
*/
const project = 'movies';
const target = 'build';
const arrayBuffer = fs.readFileSync('./angular.json');
const projects = JSON.parse(arrayBuffer).projects[project];
const bundleBudgets =
projects.architect[target].budgets ||
projects.architect[target].configurations.production.budgets;
const outputPath = projects.architect[target].options.outputPath;
const relevantFiles = fs
.readdirSync(outputPath)
.filter((name) => name.endsWith('.js') || name.endsWith('.css'));
const sizeLimitConfig = bundleBudgets
.filter(({ type, name }) => {
// does the file exist?
const fileExists = name && relevantFiles.find((f) => f.startsWith(name));
if (!fileExists && type !== 'anyComponentStyle' && type !== 'initial') {
console.log(`file: ${name}* is not in the folder ${outputPath}`);
}
return type !== 'anyComponentStyle' && fileExists;
})
.map(({ type, name, maximumError: limit }) => {
return {
gzip: false,
brotli: true,
name: 'angular-budgets--' + name || type,
path: [outputPath, type === 'initial' ? '*' : [name + '.*']].join('/'),
//limit,
};
});
return sizeLimitConfig;
}