1 | # component-builder2 [![Build Status](https://travis-ci.org/component/builder2.js.png)](https://travis-ci.org/component/builder2.js)
|
2 |
|
3 | Another version of component's builder. Some differences:
|
4 |
|
5 | - Everything is streaming!
|
6 | - Split into multiple builders
|
7 | - Much leaner `require` implementation
|
8 | - Handles newer features like globs
|
9 | - Fixes a lot of issues with the previous builder
|
10 |
|
11 | Depends on:
|
12 |
|
13 | - [resolver](https://github.com/component/resolver.js) - resolved dependency tree
|
14 | - [flatten](https://github.com/jonathanong/flatten.js) - flatten the dependency tree to create a build order
|
15 | - [require2](component/builder2.js) - this builder's `require()` implementation.
|
16 | - [manifest](https://github.com/component/manifest.js) - unglobs components' fields and creates `file` objects suitable for plugins
|
17 | - [builder-es6-module-to-cjs](https://github.com/component/builder-es6-module-to-cjs) - the included ES6 -> CJS plugin
|
18 |
|
19 | You may be interested in:
|
20 |
|
21 | - [bundler](https://github.com/component/bundler.js) - create multiple bundles from the resolved dependency tree
|
22 |
|
23 | ## Example
|
24 |
|
25 | ```js
|
26 | var fs = require('fs');
|
27 | var resolve = require('component-resolver');
|
28 | var build = require('component-builder');
|
29 |
|
30 | // resolve the dependency tree
|
31 | resolve(process.cwd(), {
|
32 | // install the remote components locally
|
33 | install: true
|
34 | }, function (err, tree) {
|
35 | if (err) throw err;
|
36 |
|
37 | // only include `.js` files from components' `.scripts` field
|
38 | build.scripts(nodes)
|
39 | .use('scripts', build.plugins.js())
|
40 | .end(function (err, string) {
|
41 | if (err) throw err;
|
42 | fs.writeFileSync('build.js', string);
|
43 | })
|
44 | .toFile('build.js');
|
45 |
|
46 | // only include `.css` files from components' `.styles` field
|
47 | build.styles(nodes)
|
48 | .use('styles', build.plugins.css())
|
49 | .end(function (err, string) {
|
50 | if (err) throw err;
|
51 | fs.writeFileSync('build.css', string);
|
52 | });
|
53 |
|
54 | // only copy `images` to the build folder
|
55 | build.files(nodes)
|
56 | .use('images', build.plugins.symlink())
|
57 | .end(); // callback optional
|
58 | })
|
59 | ```
|
60 |
|
61 | You might also want more thorough examples:
|
62 |
|
63 | - [simple-builder2-demo](http://github.com/mnmly/simple-builder2-demo): Simple demo that shows how to use plugins and build as bundles.
|
64 |
|
65 | ## Builders
|
66 |
|
67 | There are three types of builders:
|
68 |
|
69 | - [`scripts`](https://github.com/component/builder2.js/blob/master/docs/scripts.md) - streaming builder for the `Javascript` file.
|
70 | - [`styles`](https://github.com/component/builder2.js/blob/master/docs/styles.md) - streaming builder for the `CSS` file.
|
71 | - [`files`](https://github.com/component/builder2.js/blob/master/docs/files.md) - channel-based builder for everything else, which generally means copying or symlinking
|
72 |
|
73 | You'll also want to read docs on [`builder`](https://github.com/component/builder2.js/blob/master/docs/builders.md), which all three builders above inherit from.
|
74 |
|
75 | See the documentation for more information on each.
|
76 |
|
77 | ## License
|
78 |
|
79 | The MIT License (MIT)
|
80 |
|
81 | Copyright (c) 2014 Jonathan Ong me@jongleberry.com
|
82 |
|
83 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
84 | of this software and associated documentation files (the "Software"), to deal
|
85 | in the Software without restriction, including without limitation the rights
|
86 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
87 | copies of the Software, and to permit persons to whom the Software is
|
88 | furnished to do so, subject to the following conditions:
|
89 |
|
90 | The above copyright notice and this permission notice shall be included in
|
91 | all copies or substantial portions of the Software.
|
92 |
|
93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
98 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
99 | THE SOFTWARE.
|