@fe-fast/code-sweeper
Version:
A lightweight JavaScript/TypeScript code cleaning tool
35 lines (34 loc) • 1.03 kB
JavaScript
import { cleanCode } from '@fe-fast/code-sweeper';
export default function codeSweeperPlugin(options = {}) {
const finalOptions = {
...options,
rules: {
removeUnusedImports: true,
removeUnusedVariables: true,
removeConsoleLog: true,
removeDebugger: true,
formatCode: false,
renameToCamelCase: false,
...options.rules,
},
};
return {
name: 'code-sweeper',
// 在构建开始前执行代码清理
async buildStart() {
try {
await cleanCode({
...finalOptions,
path: '/Users/xueyuan/Desktop/code-sweeper/examples/vue-rollup',
// 确保不会影响构建过程
dryRun: false,
skipConfirmation: true
});
}
catch (error) {
this.error(error);
}
},
};
}
export { codeSweeperPlugin };