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 |
|
12 | This helper encapsulates the logic for loading a mako build configuration file, allowing easier
|
13 | use amongst different tools.
|
14 |
|
15 | ## Usage
|
16 |
|
17 | This module is a simple function loads and normalizes mako configuration files:
|
18 |
|
19 | ```js
|
20 | var load = require('mako-config');
|
21 |
|
22 | load('/path/to/file.json').then(function (config) {
|
23 | // config.entries
|
24 | // config.plugins
|
25 | });
|
26 | ```
|
27 |
|
28 | ## Configuration File Structure
|
29 |
|
30 | ### root
|
31 |
|
32 | If 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
|
35 | added to the mako tree, their base path will be this custom value.
|
36 |
|
37 | ### entries
|
38 |
|
39 | This will be an array of glob patterns that will be resolved to form a single list of entry files.
|
40 | The 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 |
|
54 | This will be an array of plugins to load, they can either be installed modules or point to local
|
55 | modules of your own:
|
56 |
|
57 | ```json
|
58 | {
|
59 | "plugins": [
|
60 | "mako-browser",
|
61 | "./local-plugin.js"
|
62 | ]
|
63 | }
|
64 | ```
|
65 |
|
66 | By 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 |
|
78 | When you want to load plugins or entries only in a specific `NODE_ENV`, you can create an object
|
79 | here for each of those environments. (the default env is "development")
|
80 |
|
81 | In this example, we add JS and CSS minification (via uglify and cleancss respectively) when we
|
82 | run 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 |
|
97 | The structure underneath each env is identical to the root level, and both `entries` and `plugins`
|
98 | will be appended to those defined at the root.
|
99 |
|
100 | ## API
|
101 |
|
102 | ### load(file, [overrides])
|
103 |
|
104 | This function accepts `file` as an absolute path to the configuration file. The `overrides`
|
105 | is a list of entries that will override the ones specified in the config file.
|
106 |
|
107 | It 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 |
|
115 | The same arguments are accepted, and the same result is returned synchronously.
|