What I found in the official repo of the 2020 theme that each directory contains an index.js and export content from there using loadable. Is that necessary for the theme I working on?
Also, tell me is only index.js file with exporting through loadable is necessary or something extra needed?
Hi @inamkbmail!
Thank you for your question.
I assume that by β2020 themeβ you mean @frontity/mars-theme
as is the one offered by default when you do npx frontity create your-project-name
? Pick a starter theme to clone:
β― @frontity/mars-theme (default)
@frontity/twentytwenty-theme
In that theme you have this structureβ¦
.
βββ CHANGELOG.md
βββ package.json
βββ src
βββ components
β βββ featured-media.js
β βββ header.js
β βββ index.js
β βββ link.js
β βββ list
β β βββ index.js
β β βββ list-item.js
β β βββ list.js
β β βββ pagination.js
β βββ loading.js
β βββ menu-icon.js
β βββ menu-modal.js
β βββ menu.js
β βββ nav.js
β βββ page-error.js
β βββ post.js
β βββ title.js
βββ index.js
There you can see a lot of react components directly defined under the components
folder (header
, post
, title
, etcβ¦)
Thereβs only one component (the one defined in list/index.js
) that uses loadable
to βwrapβ the component that is exported
import { loadable } from "frontity";
/**
* Codesplit the list component so it's not included if the users
* load a post directly.
*/
export default loadable(() => import("./list"));
This index
is not really mandatory for your project to work. You could import directly /components/list/list.js
instead of this /components/list/index.js
but using loadable
allows your final site to have a better performance as different (smaller) bundles are created that will be loaded only when needed (so you can improve a lot the loading speed of your site with a good loadable
strategy)
So, answering to your question
Is code splitting necessary using loadable?
No, is not really necessary: But a good idea if you want to improve the performance of your site
Hope this helps
If you have any more questions let us know
PS: If you can you provide a repository URL Iβll be able to help you better with your project/theme
Thanks for clearing things to me. β2020β means " twentytwenty-theme".
Actually I made my own theme and I felt confused about loadable
. Iβm going to announce this theme soon. TY!
Great news, canβt wait to see it
Let us know so @Reyes can help you with the announcement sharing it on our communication channels!
Iβve done announcing please check it in your feeds