vue项目内删除无用文件
vue webpack 性能优化 前端
基于vue-cli创建的项目,webpack4
安装依赖
npm i useless-files-webpack-plugin webpack-deadcode-plugin -D
配置
const DeadCodePlugin = require("webpack-deadcode-plugin");
const UselessFile = require("useless-files-webpack-plugin");
config.plugin("deadCode").use(DeadCodePlugin, [
{
patterns: ["src/**/*.*"], // 需要检测的范围
exclude: ["node_modules/**/*"], // 排除检测的范围
},
]);
config.plugin("uselessFile").use(
new UselessFile({
root: "./src", // 项目目录
out: "./fileList.json", // 输出文件列表
clean: true, // 是否删除文件,
exclude: /node_modules/, // 排除文件列表
})
);
-
webpack-deadcode-plugin
用于检查没用的文件和没用的导出,比如 export 了之后没有使用的对象
-
useless-files-webpack-plugin
只能检查出没有使用的文件,同时可以将这些文件直接删除