prelim: A Pre-build Unused Code Eliminator for JavaScript
Prelim is an unused code removal (dead code elimination) tool for javascript.Unlike other tools in this space, such as babel-minify or terserjs, prelim is focused on the "pre-build" use case: it's meant to be used outside of a build process to find and remove no-longer-used code so that humans can better read and understand their code.
You can run prelim directly on your source folder, like:
npx prelim src/
You can also use prelim in conjunction with other tools, such as a codemod or find-replace to remove a no-longer-used feature flag.
You can also use prelim as a babel plugin if you would like (although at the moment prelim provides more benefit when run outside of a build process, it can produce some savings that terserjs may not be able to identify as unused).
Usage
Installation:npm install --save-dev prelim
Useage: as a cli:
npx prelim src/directory/
Or as a babel plugin:
module.exports = {
/* ... */
plugins: [
// `loose:` enables not-strictly safe optimizations, and is recommended
// for code that does not have getters/proxies with side-effects.
// The default is `false` (equivalent to `--strict` in the cli)
['prelim', { loose: true }],
],
};