forjadev / mjo-forja-webpage

This project is the web page of the amazing forja community, it's built with React, Nextjs, Tailwind, Storybook and lots of love from the contributors.
7 stars 0 forks source link

perf: [MJO-21] - use modularizeImports to solve tree shaking issue #22

Closed kevinCubas closed 8 months ago

kevinCubas commented 1 year ago

In this pull request, is introduced a crucial optimization by implementing the modularizeImports feature with Rust Handlebars. This enhancement not only streamlines our import structure but also significantly improves the performance of our application.

Before Optimization:

Previously, the imports look like this:

import { Navbar } from '@/components';

After Optimization:

With the modularizeImports feature enabled.

import { Navbar } from '@/components'

//The modularizeImports will transform our import to look like this
// import { Navbar } from '@/components/navbar/Navbar';

Performance Improvements:

Here we are importing a Navbar component, the branch has 3 components using radix-ui and react-icons.

Large-scale Compilation (682 modules)

Before Optimization:

Compilation Time: 25.7 seconds Number of Modules: 682 modules

image

After Optimization:

Compilation Time: 15.1 seconds Number of Modules: 544 modules Percentage Reduction in Time: Approximately 40% Percentage Reduction in Modules: Approximately 20% in the total number of modules. image

Pros:

Cons:

If the component is Named "MenuMobile", then the folder must be "menuMobile" and the file "MenuMobile" with a named export inside it.