UNPKG

3.97 kBMarkdownView Raw
1# component-builder2 [![Build Status](https://travis-ci.org/component/builder2.js.png)](https://travis-ci.org/component/builder2.js)
2
3Another 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
11Depends 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](https://github.com/component/require2) - 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
19You 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
26var fs = require('fs');
27var resolve = require('component-resolver');
28var build = require('component-builder');
29
30// resolve the dependency tree
31resolve(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(tree)
39 .use('scripts', build.plugins.js())
40 .end(function (err, string) {
41 if (err) throw err;
42 fs.writeFileSync('build.js', string);
43 });
44
45 // only include `.css` files from components' `.styles` field
46 build.styles(tree)
47 .use('styles', build.plugins.css())
48 .end(function (err, string) {
49 if (err) throw err;
50 fs.writeFileSync('build.css', string);
51 });
52
53 // only copy `images` to the build folder
54 build.files(tree)
55 .use('images', build.plugins.symlink())
56 .end(); // callback optional
57})
58```
59
60You might also want more thorough examples:
61
62- [simple-builder2-demo](http://github.com/mnmly/simple-builder2-demo): Simple demo that shows how to use plugins and build as bundles.
63
64## Builders
65
66There are three types of builders:
67
68- [`scripts`](https://github.com/component/builder2.js/blob/master/docs/scripts.md) - streaming builder for the `Javascript` file.
69- [`styles`](https://github.com/component/builder2.js/blob/master/docs/styles.md) - streaming builder for the `CSS` file.
70- [`files`](https://github.com/component/builder2.js/blob/master/docs/files.md) - channel-based builder for everything else, which generally means copying or symlinking
71
72You'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.
73
74See the documentation for more information on each.
75
76## License
77
78The MIT License (MIT)
79
80Copyright (c) 2014 Jonathan Ong me@jongleberry.com
81
82Permission is hereby granted, free of charge, to any person obtaining a copy
83of this software and associated documentation files (the "Software"), to deal
84in the Software without restriction, including without limitation the rights
85to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
86copies of the Software, and to permit persons to whom the Software is
87furnished to do so, subject to the following conditions:
88
89The above copyright notice and this permission notice shall be included in
90all copies or substantial portions of the Software.
91
92THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
93IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
94FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
95AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
96LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
97OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
98THE SOFTWARE.