Treats

Treats

  • Getting Started

›Authoring Addons

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

Wrapping Up

First, pat yourself in the back and crack open a bottle of champagne! You're just about to save fellow Treats users from reinventing the wheel!

Now we're ready for the most exciting part of it all, package and ship your addons into an npm package.

Let's start by initializing an empty npm repository:

~$ mkdir my-first-addons
~$ cd my-first-addons
~$ npm init

When prompted, you can put @treats/my-first-addons or any other package as package name. With @treats/ as prefix, you're initializing your package under @treats npm scoped module.

After your npm package had been initialized, let's create our working directories to match the following structure:

my-first-addons/
|  
|-- package.json
|-- generator/
|-- helper/
|-- middleware/

Now we've just need to copy all addons that we've built in previous sections to these folders so it would look like this:

my-first-addons/
|  
|-- package.json
|-- generator/
    |-- my-life
        |-- treats-generator.js
        |-- ${NAME}.md
|-- helper/
    |-- fizzbuzz/
        |-- index.js
|-- middleware/
    |-- foobar/
        |-- index.js

After that you can just push them to npm registry with:

npm publish

When you've finished publishing the addons, now you can finally install it in your Treats project with:

yarn add @treats/my-first-addons

Now you can replace your imports in src/_server/index.js like this:

import FizzBuzzHelper from "@treats/my-first-addons/helper/fizzbuzz";
import FooBarMiddleware from "@treats/my-first-addons/middleware/foobar";

To use your generator, now you can use:

yarn generate @treats/my-first-addons/generator/my-life

Nice work! We hope you've grasped the basic concept of how addons system works in Treats. We're always amazed by how people can collaborate and create cool addons that we didn't think of before, and can't wait to see yours too!

← GeneratorsTreats Addons List →
Tokopedia Open Source
Copyright © 2019 Tokopedia OSS