-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy path.size-limit.cjs
More file actions
82 lines (80 loc) · 2.04 KB
/
.size-limit.cjs
File metadata and controls
82 lines (80 loc) · 2.04 KB
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
const limits = require("./.size-limits.json");
const checks = [
{
import: { "@apollo/client": "{ ApolloClient, InMemoryCache, HttpLink }" },
conditions: ["require"],
},
{
import: { "@apollo/client": "{ ApolloClient, InMemoryCache, HttpLink }" },
},
...[
"ApolloProvider",
"useQuery",
"useLazyQuery",
"useMutation",
"useSubscription",
"useSuspenseQuery",
"useBackgroundQuery",
"useLoadableQuery",
"useReadQuery",
"useFragment",
].map((name) => ({ import: { "@apollo/client/react": `{ ${name} }` } })),
]
.map((config) => ({
...config,
name:
config.name || config.import ?
`import ${Object.values(config.import)[0]} from "${
Object.keys(config.import)[0]
}"`
: config.path,
brotli: true,
ignore: [
...(config.ignore || []),
"react",
"react-dom",
"@graphql-typed-document-node/core",
"@wry/caches",
"@wry/context",
"@wry/equality",
"@wry/trie",
"graphql-tag",
"optimism",
"prop-types",
"response-iterator",
"symbol-observable",
"ts-invariant",
"tslib",
"zen-observable-ts",
],
}))
.flatMap((value) => [
{
...value,
conditions: ["development"].concat(
value.conditions || ["module", "browser"]
),
},
{
...value,
name: `${value.name} (production)`,
conditions: ["production"].concat(
value.conditions || ["module", "browser"]
),
},
])
.map((value) => {
const conditions = value.conditions;
delete value.conditions;
if (conditions.includes("require")) {
value.name = `${value.name} (CJS)`;
}
value.limit = limits[value.name];
value.modifyEsbuildConfig = (config) => {
config.conditions = conditions;
return config;
};
return value;
});
// useful snippet to locally run this with `size-limit --save-bundle /tmp/size --clean-dir` to debug bundle sizes
module.exports = checks; //.filter( (limit) => limit.name === Object.keys(limits).at(-1));