Skip to content

Commit 418d49f

Browse files
authored
Bundle optimizations for react components (#5459)
* feature: use ESM build of @canonical/react-components * feature: update @canonical/store-components
1 parent d05ff70 commit 418d49f

3 files changed

Lines changed: 17 additions & 60 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@canonical/cookie-policy": "3.6.5",
2929
"@canonical/global-nav": "3.8.0",
3030
"@canonical/react-components": "3.6.0",
31-
"@canonical/store-components": "0.54.2",
31+
"@canonical/store-components": "0.55.0",
3232
"@dnd-kit/core": "6.3.1",
3333
"@dnd-kit/sortable": "8.0.0",
3434
"@dnd-kit/utilities": "3.2.2",

vite.config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const flaskViteImportPlugin = () => ({
2020
const viteImports =
2121
execSync(
2222
// TODO: do it in Node to make it truly portable`
23-
`grep -rnoh --include '*.html' -e 'vite_import\\((.*)\\)'`
23+
`grep -rnoh --include '*.html' -e 'vite_import\\((.*)\\)'`,
2424
).toString() || ""; // big multi-line string wit the format
2525
// `vite_import(<filename>)`
2626

@@ -37,7 +37,7 @@ const flaskViteImportPlugin = () => ({
3737
} catch (e) {
3838
throw new Error(
3939
"Vite: Couldn't find any entry points for production build\n" +
40-
e.toString()
40+
e.toString(),
4141
);
4242
}
4343

@@ -82,6 +82,15 @@ export default defineConfig({
8282
define: {
8383
global: "globalThis", // in dev mode "randomstring" uses `global` rather than `globalThis`
8484
},
85+
resolve: {
86+
alias: [
87+
// by default react-components exports a CJS module that can't be tree-shaken, we consume the ESM instead
88+
{
89+
find: /^@canonical\/react-components$/,
90+
replacement: "@canonical/react-components/dist/esm",
91+
},
92+
],
93+
},
8594
build: {
8695
manifest: true,
8796
modulePreload: false,

yarn.lock

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -954,23 +954,6 @@
954954
dependencies:
955955
vanilla-framework "4.35.0"
956956

957-
"@canonical/react-components@1.9.0":
958-
version "1.9.0"
959-
resolved "https://registry.yarnpkg.com/@canonical/react-components/-/react-components-1.9.0.tgz#9337b35e632d7419eddf51823a5243156893185e"
960-
integrity sha512-CB2xHvGs/KFsCAbh79pSsJfg+j5Pxmye1qXCeAoirTWj1WIwRiDVV32R07Xys/bAafzINy6kStqJHkq8XUld/g==
961-
dependencies:
962-
"@types/jest" "29.5.12"
963-
"@types/node" "20.16.3"
964-
"@types/react" "18.3.5"
965-
"@types/react-dom" "18.3.0"
966-
"@types/react-table" "7.7.20"
967-
classnames "2.5.1"
968-
jest-environment-jsdom "29.7.0"
969-
lodash.isequal "4.5.0"
970-
prop-types "15.8.1"
971-
react-table "7.8.0"
972-
react-useportal "1.0.19"
973-
974957
"@canonical/react-components@3.6.0":
975958
version "3.6.0"
976959
resolved "https://registry.yarnpkg.com/@canonical/react-components/-/react-components-3.6.0.tgz#59a1c48ad6c0d4425e1a7a0f96b7d3e5d592b1bd"
@@ -987,12 +970,12 @@
987970
prop-types "15.8.1"
988971
react-table "7.8.0"
989972

990-
"@canonical/store-components@0.54.2":
991-
version "0.54.2"
992-
resolved "https://registry.yarnpkg.com/@canonical/store-components/-/store-components-0.54.2.tgz#d281835da2519530dda2b0b4faeaa6d10dac86ce"
993-
integrity sha512-FzKAHNk1d0knvICPpOcis0fGnDU3ozJ4Fnx+X6iXX5K82ZKXB5bCYlcOPwKFmuSpbvjGkpM08WS2xBqHLgn1bw==
973+
"@canonical/store-components@0.55.0":
974+
version "0.55.0"
975+
resolved "https://registry.yarnpkg.com/@canonical/store-components/-/store-components-0.55.0.tgz#4ca8d7813f1c61a687ae9e8242557a9d0fa82c63"
976+
integrity sha512-h5BJcBJ/13zzd86QspTdpX8FOdCh/lzoW3EZLjTt/eyj7DRKaDMbjIjHtkK6K6D/CvBTkKfQgwwUIyhTjkXvPA==
994977
dependencies:
995-
"@canonical/react-components" "1.9.0"
978+
"@canonical/react-components" "3.6.0"
996979
"@types/jest" "27.5.2"
997980
"@types/node" "18.19.71"
998981
"@types/react" "17.0.83"
@@ -2487,14 +2470,6 @@
24872470
jest-matcher-utils "^27.0.0"
24882471
pretty-format "^27.0.0"
24892472

2490-
"@types/jest@29.5.12":
2491-
version "29.5.12"
2492-
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.12.tgz#7f7dc6eb4cf246d2474ed78744b05d06ce025544"
2493-
integrity sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==
2494-
dependencies:
2495-
expect "^29.0.0"
2496-
pretty-format "^29.0.0"
2497-
24982473
"@types/jest@29.5.14":
24992474
version "29.5.14"
25002475
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.14.tgz#2b910912fa1d6856cadcd0c1f95af7df1d6049e5"
@@ -2531,13 +2506,6 @@
25312506
dependencies:
25322507
undici-types "~5.26.4"
25332508

2534-
"@types/node@20.16.3":
2535-
version "20.16.3"
2536-
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.16.3.tgz#7b4f9a37091cf03a0c2561bf76a9a55f03f4f523"
2537-
integrity sha512-/wdGiWRkMOm53gAsSyFMXFZHbVg7C6CbkrzHNpaHoYfsUWPg7m6ZRKtvQjgvQ9i8WT540a3ydRlRQbxjY30XxQ==
2538-
dependencies:
2539-
undici-types "~6.19.2"
2540-
25412509
"@types/node@20.17.19":
25422510
version "20.17.19"
25432511
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.17.19.tgz#0f2869555719bef266ca6e1827fcdca903c1a697"
@@ -2560,13 +2528,6 @@
25602528
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.26.tgz#fa7891ba70fd39ddbaa7e85b6ff9175bb546bc1b"
25612529
integrity sha512-Z+2VcYXJwOqQ79HreLU/1fyQ88eXSSFh6I3JdrEHQIfYSI0kCQpTGvOrbE6jFGGYXKsHuwY9tBa/w5Uo6KzrEg==
25622530

2563-
"@types/react-dom@18.3.0":
2564-
version "18.3.0"
2565-
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.3.0.tgz#0cbc818755d87066ab6ca74fbedb2547d74a82b0"
2566-
integrity sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==
2567-
dependencies:
2568-
"@types/react" "*"
2569-
25702531
"@types/react-dom@19.0.4":
25712532
version "19.0.4"
25722533
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-19.0.4.tgz#bedba97f9346bd4c0fe5d39e689713804ec9ac89"
@@ -2610,14 +2571,6 @@
26102571
"@types/scheduler" "^0.16"
26112572
csstype "^3.0.2"
26122573

2613-
"@types/react@18.3.5":
2614-
version "18.3.5"
2615-
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.5.tgz#5f524c2ad2089c0ff372bbdabc77ca2c4dbadf8f"
2616-
integrity sha512-WeqMfGJLGuLCqHGYRGHxnKrXcTitc6L/nBUWfWPcTarG3t9PsquqUMuVeXZeca+mglY4Vo5GZjCi0A3Or2lnxA==
2617-
dependencies:
2618-
"@types/prop-types" "*"
2619-
csstype "^3.0.2"
2620-
26212574
"@types/react@19.0.10":
26222575
version "19.0.10"
26232576
resolved "https://registry.yarnpkg.com/@types/react/-/react-19.0.10.tgz#d0c66dafd862474190fe95ce11a68de69ed2b0eb"
@@ -6075,11 +6028,6 @@ lodash.debounce@^4.0.8:
60756028
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
60766029
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==
60776030

6078-
lodash.isequal@4.5.0:
6079-
version "4.5.0"
6080-
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
6081-
integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==
6082-
60836031
lodash.isplainobject@^4.0.6:
60846032
version "4.0.6"
60856033
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"

0 commit comments

Comments
 (0)