Treats

Treats

  • Getting Started

›Main Concepts

Getting Started

  • Installation

Tutorial

  • 01. Creating Your First Page
  • 02. Using Redux
  • 03. Using GraphQL
  • 04. Fetch Data for SSR
  • 05. Adding Addons

Main Concepts

  • Overview
  • Routing
  • Localization
  • Code-splitting
  • Redux
  • GraphQL Client
  • Middlewares
  • Helpers
  • Server-side Events
  • Server-side Template
  • Server-side Rendering
  • Custom Server App
  • Custom Client Initialization
  • Custom React App
  • Runtime Config
  • Build Config
  • Environment Variables
  • Code Generator
  • Scripts
  • Addons
  • Typescript
  • Workbox

API Reference

  • Overview
  • Filesystem Hooks
  • Components
  • Server
  • Client
  • Router
  • Intl
  • Locale Data
  • Helmet
  • Redux
  • Graphql

Authoring Addons

  • Overview
  • Helpers
  • Middlewares
  • Generators
  • Wrapping Up

Addons

  • Treats Addons List

Contributing

  • How To Contribute

FAQ

  • FAQs

Code-splitting

The basic concept of code-splitting is to split single big bundle of our app into separate small chunks that can be loaded on demand. Code-splitting can be done on route level or even component level. Setting up code-splitting for modern JavaScript web apps was notoriously known to be a painful process. Let alone make it work with Hot Module Replacement on development build.

To solve this problem we will use 2 main building blocks of code-splitting in Treats, the AsyncLoader and AsyncComponent, in the future, we might not need 2 separate components to do code-splitting, but for now we found out that this is the less painful way to do code-splitting while keeping the HMR capabilities on development mode.

AsyncLoader and AsyncComponent

AsyncLoader that was build on top of react-universal-component act as the code-splitting entry for our async bundle:

// page/home/index.js
import AsyncLoader from "@treats/component/async-loader";

const Home = AsyncLoader({ component: import("./home") });

export default Home;

AsyncComponent that was build on top of react-hot-loader act as the hot-module-replacement enabler for our async bundler

// page/home/home.js
import AsyncComponent from "@treats/component/async-component";

const Home = () => <div>Home!<div/>;

export default AsyncComponent(module, Home);

More information about how to customize loading, error placeholder etc for AsyncLoader can be found here

← LocalizationRedux →
Tokopedia Open Source
Copyright © 2019 Tokopedia OSS