build: remove unnecessary webpack plugins (#6386)

* build: remove duplicate file case check

* build: remove unused moment tree-shaking

* fix: nits
This commit is contained in:
Zach Pomerantz 2023-04-20 14:12:43 -07:00 committed by GitHub
parent 5e090db8b3
commit b6874b8094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 16 deletions

@ -31,6 +31,11 @@ module.exports = {
'error', 'error',
{ {
paths: [ paths: [
{
name: 'moment',
// tree-shaking for moment is not configured because it degrades performance - see craco.config.cjs.
message: 'moment is not configured for tree-shaking. If you use it, update the Webpack configuration.',
},
{ {
name: 'zustand', name: 'zustand',
importNames: ['default'], importNames: ['default'],

@ -2,7 +2,8 @@
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin') const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin')
const { execSync } = require('child_process') const { execSync } = require('child_process')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { DefinePlugin } = require('webpack') const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const { DefinePlugin, IgnorePlugin } = require('webpack')
const commitHash = execSync('git rev-parse HEAD').toString().trim() const commitHash = execSync('git rev-parse HEAD').toString().trim()
const isProduction = process.env.NODE_ENV === 'production' const isProduction = process.env.NODE_ENV === 'production'
@ -51,7 +52,8 @@ module.exports = {
webpack: { webpack: {
plugins: [new VanillaExtractPlugin({ identifiers: 'short' })], plugins: [new VanillaExtractPlugin({ identifiers: 'short' })],
configure: (webpackConfig) => { configure: (webpackConfig) => {
webpackConfig.plugins = webpackConfig.plugins.map((plugin) => { webpackConfig.plugins = webpackConfig.plugins
.map((plugin) => {
// Extend process.env with dynamic values (eg commit hash). // Extend process.env with dynamic values (eg commit hash).
// This will make dynamic values available to JavaScript only, not to interpolated HTML (ie index.html). // This will make dynamic values available to JavaScript only, not to interpolated HTML (ie index.html).
if (plugin instanceof DefinePlugin) { if (plugin instanceof DefinePlugin) {
@ -68,6 +70,16 @@ module.exports = {
return plugin return plugin
}) })
.filter((plugin) => {
// Case sensitive paths are enforced by TypeScript.
// See https://www.typescriptlang.org/tsconfig#forceConsistentCasingInFileNames.
if (plugin instanceof CaseSensitivePathsPlugin) return false
// IgnorePlugin is used to tree-shake moment locales, but we do not use moment in this project.
if (plugin instanceof IgnorePlugin) return false
return true
})
// We're currently on Webpack 4.x which doesn't support the `exports` field in package.json. // We're currently on Webpack 4.x which doesn't support the `exports` field in package.json.
// Instead, we need to manually map the import path to the correct exports path (eg dist or build folder). // Instead, we need to manually map the import path to the correct exports path (eg dist or build folder).