UNPKG

4 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(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
61You 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
67There 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
73You'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
75See the documentation for more information on each.
76
77## License
78
79The MIT License (MIT)
80
81Copyright (c) 2014 Jonathan Ong me@jongleberry.com
82
83Permission is hereby granted, free of charge, to any person obtaining a copy
84of this software and associated documentation files (the "Software"), to deal
85in the Software without restriction, including without limitation the rights
86to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
87copies of the Software, and to permit persons to whom the Software is
88furnished to do so, subject to the following conditions:
89
90The above copyright notice and this permission notice shall be included in
91all copies or substantial portions of the Software.
92
93THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
94IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
95FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
96AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
97LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
98OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
99THE SOFTWARE.