UNPKG

3.92 kBMarkdownView Raw
1# mako-config
2
3> A helper for loading [mako][mako] build config from a file.
4
5[![npm version][npm-badge]][npm]
6[![build status][travis-badge]][travis]
7[![coverage][coveralls-badge]][coveralls]
8[![npm dependencies][david-badge]][david]
9[![npm dev dependencies][david-dev-badge]][david-dev]
10[![code style][standard-badge]][standard]
11
12This helper encapsulates the logic for loading a mako build configuration file,
13allowing easier use 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
35when these files are added to the mako tree, their base path will be this
36custom value.
37
38### entries
39
40This will be an array of glob patterns that will be resolved to form a single
41list of entry files. The patterns will all be resolved relative to the config
42file's location.
43
44```json
45{
46 "entries": [
47 "index.{js,css}",
48 "pages/**/index.{js,css}",
49 "public/**"
50 ]
51}
52```
53
54### plugins
55
56This will be an array of plugins to load, they can either be installed modules
57or point to local modules of your own:
58
59```json
60{
61 "plugins": [
62 "mako-browser",
63 "./local-plugin.js"
64 ]
65}
66```
67
68By default, no arguments will be passed during initialization. To change this,
69use an array:
70
71```json
72{
73 "plugins": [
74 [ "mako-browser", { "output": "dist" } ]
75 ]
76}
77```
78
79### concurrency
80
81If you want to set the concurrency level, you can use this property as a number.
82
83### env
84
85When you want to load plugins or entries only in a specific `NODE_ENV`, you can
86create an object here for each of those environments. (the default env is
87"development")
88
89In this example, we add JS and CSS minification (via uglify and cleancss
90respectively) when we run with `NODE_ENV=production`:
91
92```json
93{
94 "env": {
95 "production": {
96 "plugins": [
97 "mako-uglify",
98 "mako-cleancss"
99 ]
100 }
101 }
102}
103```
104
105The structure underneath each env is identical to the root level, and both
106`entries` and `plugins` will be appended to those defined at the root.
107
108## API
109
110### load(file, [overrides])
111
112This function accepts `file` as an absolute path to the configuration file. The
113`overrides` is a list of entries that will override the ones specified in the
114config file.
115
116It returns a promise that resolves with an object. It will contain the following
117keys:
118
119 - `root`: the absolute path to an alternate root (`null` if not specified)
120 - `entries`: an array of absolute file paths to all the matched entry files
121 - `plugins`: an array of the initialized plugin functions
122 - `concurrency`: a number for concurrency if included in the config file
123 - `path`: the absolute path to the file that was loaded (aka: `file`)
124 - `original`: a copy of the original JSON structure
125
126### load.sync(file, [overrides])
127
128The same arguments are accepted, and the same result is returned synchronously.
129
130
131[mako]: https://github.com/makojs/core
132[coveralls]: https://coveralls.io/github/makojs/config
133[coveralls-badge]: https://img.shields.io/coveralls/makojs/config.svg
134[david]: https://david-dm.org/makojs/config
135[david-badge]: https://img.shields.io/david/makojs/config.svg
136[david-dev]: https://david-dm.org/makojs/config#info=devDependencies
137[david-dev-badge]: https://img.shields.io/david/dev/makojs/config.svg
138[npm]: https://www.npmjs.com/package/mako-config
139[npm-badge]: https://img.shields.io/npm/v/mako-config.svg
140[standard]: http://standardjs.com/
141[standard-badge]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
142[travis]: https://travis-ci.org/makojs/config
143[travis-badge]: https://img.shields.io/travis/makojs/config.svg