forked from ai/size-limit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (49 loc) · 1.69 KB
/
index.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
import _StatoscopeWebpackPlugin from '@statoscope/webpack-plugin'
import { join } from 'node:path'
function addStatoscope(limitConfig, check, webpackConfig) {
let StatoscopeWebpackPlugin = _StatoscopeWebpackPlugin.default ? _StatoscopeWebpackPlugin.default : _StatoscopeWebpackPlugin;
if (limitConfig.why) {
let shouldOpen = process.env.NODE_ENV !== 'test' && !limitConfig.saveBundle
webpackConfig.plugins.push(
new StatoscopeWebpackPlugin({
additionalStats: [limitConfig.compareWith, check.compareWith].filter(
Boolean
),
name: limitConfig.project,
open: shouldOpen ? 'file' : false,
reports: check.uiReports || [],
saveReportTo: limitConfig.saveBundle
? join(limitConfig.saveBundle, 'report.html')
: undefined,
saveStatsTo: limitConfig.saveBundle
? join(limitConfig.saveBundle, 'stats.json')
: undefined,
watchMode: limitConfig.watch
})
)
} else if (limitConfig.saveBundle) {
webpackConfig.plugins.push(
new StatoscopeWebpackPlugin({
open: false,
saveReportTo: join(limitConfig.saveBundle, 'report.html'),
saveStatsTo: join(limitConfig.saveBundle, 'stats.json'),
watchMode: limitConfig.watch
})
)
}
}
export default [
{
async before(config, check) {
let modifyConfig = check.modifyWebpackConfig
check.modifyWebpackConfig = function modifyWebpackConfig(webpackConfig) {
addStatoscope(config, check, webpackConfig)
if (modifyConfig) {
return modifyConfig(webpackConfig) || webpackConfig
}
return webpackConfig
}
},
name: '@size-limit/webpack-why'
}
]