Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 22, 2018
1 parent 98c43a2 commit 5dec13a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
13 changes: 11 additions & 2 deletions docs/config.md
Expand Up @@ -2,15 +2,24 @@

This document describes the `cush.config.js` module, which is used to configure the bundles of a project.

Most changes to the `cush.config.js` module take effect immediately.

## `bundles` object

The `bundles` object defines options for bundles.

Each key is the path to a bundle's main module (relative to the project root).

Each value is an [options][opts] object.
Each value is an object with these properties:
- `format: ?Function`
- `plugins: ?(string|Function|Object)[]`
- `init: ?Function`

The `format` option forces the given bundle format to be used. You must recreate the bundle for changes to this option to take effect.

The `plugins` option has values explained [here.](./plugins.md#using-a-plugin)

[opts]: ./fs.md#creating-a-bundle
The `init` option is called whenever the bundle is being configured.

```js
exports.bundles = {
Expand Down
45 changes: 33 additions & 12 deletions docs/fs.md
Expand Up @@ -12,7 +12,6 @@ Available options are:
- `dev: ?boolean`
- `target: string`
- `plugins: ?(string|Function|Object)[]`
- `parsers: ?string[]`
- `format: ?Function`

The `dev` option is used by plugins and formats. Your `cush.config.js` module may even use it. The default value is `false`, which indicates a "production" bundle should be generated.
Expand All @@ -21,8 +20,6 @@ The `target` is required. Common values are `web`, `ios`, and `android`.

The `plugins` option is identical to calling `Bundle#use` with the same value. [Learn more](./plugins.md#using-a-plugin)

The `parsers` option is an array of filenames that are imported in all workers. [Learn more](./workers.md#parseextasset-asset-pack-object)

The `format` option is explained on [this page.](./formats.md)

 
Expand Down Expand Up @@ -69,19 +66,21 @@ The array of plugins that you passed to `cush.bundle`.

If you mutate this after calling `read` at least once, you must call `unload` to reset the bundle.

#### `parsers: string[]`

The array of parsers that you passed to `cush.bundle`.

If you mutate this after calling `read` at least once, you must call `unload` to reset the bundle.

#### `project: Project`

The project that owns this bundle.

#### `valid: boolean`
#### `status: number`

Equals `false` if a new build is required on the next read.
The bundle status:
```js
INIT = 1 // never built before
LAZY = 2 // no automatic rebuilds
IDLE = 3 // waiting for changes
REDO = 4 // scheduled to rebuild
BUSY = 5 // build in progress
DONE = 6 // build complete
```

#### `state: Object`

Expand Down Expand Up @@ -155,13 +154,35 @@ Once this is called, you'll need to use `cush.bundle` if you need the same bundl

You *must* call this to properly clean up the worker farm and stop any file watchers.

### Events

Events are *not* hooks. Your listeners won't be removed when the bundle is reconfigured, and you add listeners with the `on` method. [Learn more](https://github.com/cushJS/events) about event-related methods.

#### `async change(event: Object, pack: Package)`

A package watched by the bundle had an asset added, changed, or deleted.

#### `async invalidate()`

The last build is now outdated.

#### `rebuild()`

The next build is starting.

At risk of stating the obvious, the first build does *not* trigger this event.

#### `async destroy()`

The bundle had its [`destroy`](#destroy-void) method called.

### Hooks

Here are hooks provided by the bundler by default. Remember that plugins and bundle formats can provide their own hooks, so read their documentation too.

#### `asset(asset: Asset, state: Object)`

Called on every build for every asset used by the bundle. The asset may have been in the previous build or entirely new. The `state` object is equivalent to `asset.owner.bundle.state`, which is reset at the start of every build.
Called on every build for every asset used by the bundle. The asset may have been in the previous build or entirely new. The `state` object is reset at the start of every build.

#### `package(pack: Package, state: Object)`

Expand Down

0 comments on commit 5dec13a

Please sign in to comment.