mako-config
Module for loading mako config from a file.
Last updated 2 years ago by dominicbarnes .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mako-config 
SYNC missed versions from official npm registry.

mako-config

A helper for loading mako build config from a file.

npm version npm dependencies npm dev dependencies

This helper is for loading mako build configuration, allowing easy use among different tools.

Usage

var load = require('mako-config')

// async
load().then(function (config) {
  // config.entries
  // config.plugins
})

// sync
let config = load.sync()
// config.entries
// config.plugins

Configuration File Structure

If you are using a standalone file, (eg: .makorc) the structure below will be the entire JSON object contained. If you are using a package.json, the JSON will be contained by a property. (the default is mako)

root

If specified, this allows you to set a custom root/base path for entries.

NOTE: paths are still resolved relative to the config file location, but when these files are added to the mako tree, their base path will be this custom value.

entries

This will be an array of glob patterns that will be resolved to form a single list of entry files. The patterns will all be resolved relative to the config file's location.

{
  "entries": [
    "index.{js,css}",
    "pages/**/index.{js,css}",
    "public/**"
  ]
}

plugins

This will be an array of plugins to load, they can either be installed modules or point to local modules of your own:

{
  "plugins": [
    "mako-browser",
    "./local-plugin.js"
  ]
}

By default, no arguments will be passed during initialization. To change this, use an array:

{
  "plugins": [
    [ "mako-browser", { "output": "dist" } ]
  ]
}

concurrency

If you want to set the concurrency level, you can use this property as a number.

env

When you want to load plugins or entries only in a specific NODE_ENV, you can create an object here for each of those environments. (the default env is "development")

In this example, we add JS and CSS minification (via uglify and cleancss respectively) when we run with NODE_ENV=production:

{
  "env": {
    "production": {
      "plugins": [
        "mako-uglify",
        "mako-cleancss"
      ]
    }
  }
}

The structure underneath each env is identical to the root level, and both entries and plugins will be appended to those defined at the root.

API

load([options])

This function loads mako config starting for a project.

It starts in the dir and searches up for a standalone file first, such as a .makorc. If one is found, that is taken immediately. (there is no cascade)

If this yields no config, it will then search for the nearest package.json in a similar fashion, looking for one with the mako property.

If no valid configuration is found, the promise will be rejected.

Available options:

  • dir the starting directory (default: pwd)
  • filename the config filename to search for (default: .makorc)
  • property the package.json property to use (default: mako)
  • overrides user-supplied overrides for the entries

It returns a promise that resolves with an object. It will contain the following keys:

  • root: the absolute path to an alternate root (null if not specified)
  • entries: an array of absolute file paths to all the matched entry files
  • plugins: an array of the initialized plugin functions
  • concurrency: a number for concurrency if included in the config file
  • path: the absolute path to the file that was loaded (aka: file)
  • env: the known environment used for this config (eg: "development")
  • original: a copy of the original JSON structure

load.sync([options])

The same arguments are accepted, and the same result is returned synchronously. (any errors will be thrown as an exception)

Current Tags

  • 2.0.1                                ...           latest (2 years ago)

21 Versions

  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.5.2                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           3 years ago
  • 0.4.4                                ...           3 years ago
  • 0.4.3                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (11)
Dev Dependencies (0)
None
Dependents (2)

Copyright 2014 - 2016 © taobao.org |