-
Notifications
You must be signed in to change notification settings - Fork 0
/
.size-limit.cjs
80 lines (76 loc) · 2.3 KB
/
.size-limit.cjs
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
// @ts-check
const fullEsmMaxSize = '5KB'
// Recent Nextjs version have some optimizations for commonjs that
// aren't available on bare-bone webpack. don't worry about threshold
// difference here for cjs. We can keep this till cjs is supported.
const fullCjsMaxSize = '29KB'
const getSimpleExamplePageLimits = () => {
const dir = './examples/simple/.next'
let manifest
try {
manifest = require(`${dir}/build-manifest.json`)
} catch (e) {
throw new Error(
'Cannot find a NextJs build folder, did you forget to run build:examples ?'
)
}
const limitCfg = {
defaultSize: '90kb',
pages: {
'/': '85kb',
'/404': '90kb',
'/_app': '105kb',
'/_error': '82Kb',
'/second-page': '85Kb',
},
}
let pageLimits = []
for (const [uri, paths] of Object.entries(manifest.pages)) {
pageLimits.push({
name: `Example app: page '${uri}'`,
limit: limitCfg.pages?.[uri] ?? limitCfg.defaultSize,
webpack: false,
path: paths.map(p => `${dir}/${p}`),
})
}
return pageLimits
}
const modifyWebpackConfig = config => {
config.resolve = {}
config.resolve.fallback = { path: false, fs: false }
}
/**
* Will ensure esm tree-shakeability and total size are within expectations.
*
* @link https://github.com/ai/size-limit/
* @type {{name: string, path: string[], limit: string, import?: string, webpack?: boolean, modifyWebpackConfig: any}[]}
*/
module.exports = [
// ###################################################
// Dist ESM full bundle
// ###################################################
{
name: 'ESM (import everything *)',
path: ['dist/esm/index.js'],
import: '*',
limit: fullEsmMaxSize,
modifyWebpackConfig,
},
// ###################################################
// Fist commonjs full bundle
// Tip: older versions of nextjs will not tree-shake
// cjs very well. This explains threshold differences
// ###################################################
{
name: 'CJS (require everything *)',
path: ['dist/commonjs/index.js'],
import: '*',
webpack: true,
limit: fullCjsMaxSize,
modifyWebpackConfig,
},
// ###################################################
// Example apps
// ###################################################
...getSimpleExamplePageLimits(),
]