UNPKG

3.28 kBMarkdownView Raw
1# mako-config
2
3> A helper for loading mako build config from a file.
4
5[![npm version](https://img.shields.io/npm/v/mako-config.svg)](https://www.npmjs.com/package/mako-config)
6[![build status](https://img.shields.io/travis/makojs/config.svg)](https://travis-ci.org/makojs/config)
7[![coverage](https://img.shields.io/coveralls/makojs/config.svg)](https://coveralls.io/github/makojs/config)
8[![npm dependencies](https://img.shields.io/david/makojs/config.svg)](https://david-dm.org/makojs/config)
9[![npm dev dependencies](https://img.shields.io/david/dev/makojs/config.svg)](https://david-dm.org/makojs/config#info=devDependencies)
10[![code style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
11
12This helper encapsulates the logic for loading a mako build configuration file, allowing easier
13use amongst different tools.
14
15## Usage
16
17This module is a simple function loads and normalizes mako configuration files:
18
19```js
20var load = require('mako-config');
21
22load('/path/to/file.json').then(function (config) {
23 // config.entries
24 // config.plugins
25});
26```
27
28## Configuration File Structure
29
30### root
31
32If specified, this allows you to set a custom root/base path for you `entries`.
33
34**NOTE:** paths are still resolved relative to the config file location, but when these files are
35added to the mako tree, their base path will be this custom value.
36
37### entries
38
39This will be an array of glob patterns that will be resolved to form a single list of entry files.
40The patterns will all be resolved relative to the config file's location.
41
42```json
43{
44 "entries": [
45 "index.{js,css}",
46 "pages/**/index.{js,css}",
47 "public/**"
48 ]
49}
50```
51
52### plugins
53
54This will be an array of plugins to load, they can either be installed modules or point to local
55modules of your own:
56
57```json
58{
59 "plugins": [
60 "mako-browser",
61 "./local-plugin.js"
62 ]
63}
64```
65
66By default, no arguments will be passed during initialization. To change this, use an array:
67
68```json
69{
70 "plugins": [
71 [ "mako-browser", { "output": "dist" } ]
72 ]
73}
74```
75
76### env
77
78When you want to load plugins or entries only in a specific `NODE_ENV`, you can create an object
79here for each of those environments. (the default env is "development")
80
81In this example, we add JS and CSS minification (via uglify and cleancss respectively) when we
82run with `NODE_ENV=production`:
83
84```json
85{
86 "env": {
87 "production": {
88 "plugins": [
89 "mako-uglify",
90 "mako-cleancss"
91 ]
92 }
93 }
94}
95```
96
97The structure underneath each env is identical to the root level, and both `entries` and `plugins`
98will be appended to those defined at the root.
99
100## API
101
102### load(file, [overrides])
103
104This function accepts `file` as an absolute path to the configuration file. The `overrides`
105is a list of entries that will override the ones specified in the config file.
106
107It returns a promise that resolves with an object. It will contain the following keys:
108
109 - `root`: the absolute path to an alternate root (`null` if not specified)
110 - `entries`: an array of absolute file paths to all the matched entry files
111 - `plugins`: an array of the initialized plugin functions
112
113### load.sync(file, [overrides])
114
115The same arguments are accepted, and the same result is returned synchronously.