From 4adb42e42695f38a330fdead628d5b2610a8e8ba Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 14 Apr 2022 15:22:37 -0500 Subject: [PATCH] Webpack: add DeadCodePlugin to detect unused files --- package.json | 1 + webpack/shared.js | 14 ++++++++++++++ yarn.lock | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/package.json b/package.json index 4caec0c8d..89d94fa92 100644 --- a/package.json +++ b/package.json @@ -191,6 +191,7 @@ "webpack-assets-manifest": "^5.0.6", "webpack-bundle-analyzer": "^4.4.2", "webpack-cli": "^4.8.0", + "webpack-deadcode-plugin": "^0.1.16", "webpack-merge": "^5.8.0", "wicg-inert": "^3.1.1" }, diff --git a/webpack/shared.js b/webpack/shared.js index 0ccd628cb..8135fa512 100644 --- a/webpack/shared.js +++ b/webpack/shared.js @@ -9,6 +9,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const webpack = require('webpack'); const AssetsManifestPlugin = require('webpack-assets-manifest'); +const DeadCodePlugin = require('webpack-deadcode-plugin'); const { env, settings, output } = require('./configuration'); const rules = require('./rules'); @@ -86,6 +87,19 @@ module.exports = { writeToDisk: true, publicPath: true, }), + // https://github.com/MQuy/webpack-deadcode-plugin + new DeadCodePlugin({ + patterns: [ + 'app/**/*', + ], + exclude: [ + '**/*.test.*', + '**/__*__/*', + '**/(LICENSE|README|COPYING)(.md|.txt)?', + // This file is imported with @preval + 'app/soapbox/features/emoji/emoji_map.json', + ], + }), // https://github.com/jantimon/html-webpack-plugin#options new HtmlWebpackPlugin(makeHtmlConfig()), new HtmlWebpackPlugin(makeHtmlConfig({ filename: '404.html' })), diff --git a/yarn.lock b/yarn.lock index 9ed45677b..ece5c1947 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10786,6 +10786,14 @@ webpack-cli@^4.8.0: v8-compile-cache "^2.2.0" webpack-merge "^5.7.3" +webpack-deadcode-plugin@^0.1.16: + version "0.1.16" + resolved "https://registry.yarnpkg.com/webpack-deadcode-plugin/-/webpack-deadcode-plugin-0.1.16.tgz#f58ec7bd908325247396438a50afc209bfd01bdd" + integrity sha512-T3oRlzftN4jU8Wm8rjx9mzYC8zr4CND5kNgh6EBJyhWy68F5kZ334EjdBjOKDEpUHuybBuxi/SviVUFsP0gx4g== + dependencies: + chalk "^3.0.0" + fast-glob "^3.1.1" + webpack-dev-middleware@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-5.1.0.tgz#90a645b077e85f661c5bb967dc32adc3eceb5cfd"