A rollup plugin that fails when you have dead code anywhere
npm install rollup-plugin-dce

Install the package from npm:
$ npm install --save-dev rollup rollup-plugin-dce
Add it to your rollup.config.js:
``js
import dce from "rollup-plugin-dce";
const config = [
{
input: "./src/index.ts",
output: [{ file: "dist/my-library.js", format: "cjs" }, { file: "dist/my-library.mjs", format: "es" }],
plugins: [
ts(),
dce({
sourceGlob: "./src/*/.ts",
}),
],
},
];
export default config;
`
For TypeScript projects, this plugin integrates with
rollup-plugin-dts
and can report dead non-emit items, such as interface and type declarations.
As this requires two passes, one for the transpiled .js code, and another for.d.ts
the type definitions of files, using this plugin as part of arollup.config can lead to false positives.
For this reason, it is recommended to programmatically analyze a TypeScript
project like so:
`ts
import { analyzeTSProject } from "rollup-plugin-dce";
const { files: filesWithDeadCode } = await analyzeTSProject({
input: "./src/index.ts",
sourceGlob: "./src/*/.ts",
});
``