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

Treats with Workbox

Treats provides Workbox support in building your application. Workbox is a libary that makes caching assets on your application much easier so it can improve your application's performance and resilience in unstable condition.

Treats using a webpack plugin called workbox-webpack-plugin to implement Workbox. Workbox configuration can be set and enabled on your project from your project's treats build config (treats.config.js) as can be seen in here build config file without needing to install and add any of workbox dependencies.

Configuring Workbox inside Treats Build Config file

Here's an example on how to enable your workbox configuration on treats.config.js:

// treats.config.js
...
const config: {
    ...
    webpack: {
        ...
        workbox: {
            pluginMode: "InjectManifest",
            serviceWorkerFilename: "sw.js",
            options: {
                swSrc: "./src/sw.js",
                include: /\.(html|css|js)$/
            }
        }
    }
}

Your configuration should be placed inside workbox object inside of webpack's config. There's several variable that can be inputted here:

  • pluginMode: plugin classes that are provided by workbox-webpack-plugin. There's two plugins that can be used such as:
    • GenerateSW: Automatically generate a service worker.
    • InjectManifest: Injecting list of precached assets into a service worker file. If you're using this plugin, swSrc must be included in option.
  • serviceWorkerFilename: The name of the service worker output file. Will be defaulted to service-worker.js if this variable left empty.
  • options: Configuration options that to be added as the plugin's option in workbox-webpack-plugin. More info on what options that available to be added can be found here.
← Working with TypescriptOverview →
Tokopedia Open Source
Copyright © 2019 Tokopedia OSS