0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed treeshaking for lodash in AdminX apps

refs https://dev.to/pffigueiredo/making-lodash-tree-shakable-3h27
ref https://linear.app/tryghost/issue/DEV-20/faster-builds

- by importing `lodash`, we import a huge 500KB file into all AdminX
  apps
- we only use one function from this, so we can switch to `lodash-es`
  and Vite will treeshake the rest out of the final compiled JS
- this saves 500KB in each AdminX app and improves compile times
This commit is contained in:
Daniel Lockyer 2024-09-03 09:51:21 +02:00 committed by Daniel Lockyer
parent 84b45581b6
commit 7db1cb4f14
3 changed files with 19 additions and 5 deletions

View file

@ -28,25 +28,27 @@
], ],
"devDependencies": { "devDependencies": {
"@codemirror/lang-html": "6.4.9", "@codemirror/lang-html": "6.4.9",
"@radix-ui/react-tooltip": "1.1.2",
"@storybook/addon-essentials": "7.6.20", "@storybook/addon-essentials": "7.6.20",
"@storybook/addon-interactions": "7.6.20", "@storybook/addon-interactions": "7.6.20",
"@storybook/addon-links": "7.6.20", "@storybook/addon-links": "7.6.20",
"@radix-ui/react-tooltip": "1.1.2",
"@storybook/addon-styling": "1.3.7", "@storybook/addon-styling": "1.3.7",
"@storybook/blocks": "7.6.20", "@storybook/blocks": "7.6.20",
"@storybook/react": "7.6.20", "@storybook/react": "7.6.20",
"@storybook/react-vite": "7.6.4", "@storybook/react-vite": "7.6.4",
"@storybook/testing-library": "0.2.2", "@storybook/testing-library": "0.2.2",
"@testing-library/react": "14.3.1", "@testing-library/react": "14.3.1",
"@testing-library/react-hooks" : "8.0.1", "@testing-library/react-hooks": "8.0.1",
"@types/lodash-es": "4.17.12",
"@vitejs/plugin-react": "4.2.1", "@vitejs/plugin-react": "4.2.1",
"c8": "8.0.1", "c8": "8.0.1",
"chai": "4.3.8",
"eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-react-refresh": "0.4.3", "eslint-plugin-react-refresh": "0.4.3",
"eslint-plugin-tailwindcss": "3.13.0", "eslint-plugin-tailwindcss": "3.13.0",
"jsdom": "24.1.3", "jsdom": "24.1.3",
"lodash-es": "4.17.21",
"mocha": "10.2.0", "mocha": "10.2.0",
"chai": "4.3.8",
"react": "18.3.1", "react": "18.3.1",
"react-dom": "18.3.1", "react-dom": "18.3.1",
"rollup-plugin-node-builtins": "2.1.2", "rollup-plugin-node-builtins": "2.1.2",

View file

@ -1,6 +1,6 @@
import {arrayMove} from '@dnd-kit/sortable'; import {arrayMove} from '@dnd-kit/sortable';
import {useEffect, useState} from 'react'; import {useEffect, useState} from 'react';
import _ from 'lodash'; import * as _ from 'lodash-es';
export type SortableIndexedList<Item> = { export type SortableIndexedList<Item> = {
items: Array<{ item: Item; id: string }>; items: Array<{ item: Item; id: string }>;

View file

@ -8416,6 +8416,18 @@
dependencies: dependencies:
keyv "*" keyv "*"
"@types/lodash-es@4.17.12":
version "4.17.12"
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.12.tgz#65f6d1e5f80539aa7cfbfc962de5def0cf4f341b"
integrity sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==
dependencies:
"@types/lodash" "*"
"@types/lodash@*":
version "4.17.7"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.7.tgz#2f776bcb53adc9e13b2c0dfd493dfcbd7de43612"
integrity sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==
"@types/lodash@^4.14.165", "@types/lodash@^4.14.167": "@types/lodash@^4.14.165", "@types/lodash@^4.14.167":
version "4.14.194" version "4.14.194"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76"
@ -22019,7 +22031,7 @@ locate-path@^7.1.0:
dependencies: dependencies:
p-locate "^6.0.0" p-locate "^6.0.0"
lodash-es@^4.17.11, lodash-es@^4.17.15: lodash-es@4.17.21, lodash-es@^4.17.11, lodash-es@^4.17.15:
version "4.17.21" version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee" resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw== integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==