UNPKG

3.47 kBMarkdownView Raw
1# r-build
2r/Build aims to be a configurable build system for ES6/7 projects based on on Webpack. Out of the box it includes some default configurations for building clients (all pre-packaked, minifed, and tree-shaken), and servers (common code bundled into a vendor file that node can run). It can also handle less/css (defining sass is easy and left as an excercise for the reader), and webfonts
3
4### Generators
5r/Build is built off a system of defining shorthand for webpack build configurations. This way you can define configs via simple names if you want to build your own config. The goal being you can define your own configs (as `/<project-root>/blueprints.config.js`) that either:
6* use the built in generators via their shorthand name e.g. `esnextreact` (to read how its configured, read into [/lib/generators/loaders/index.js](https://github.com/schwers/r-build/blob/master/lib/generators/loaders/index.js) and [/lib/makeBuild.js](https://github.com/schwers/r-build/blob/master/lib/makeBuild.js))
7* pass in a on object that with arguments to give to built in generators:
8
9 ```javascript
10 resolve: {
11 generator: 'npm-and-modules',
12 extensions: ['', '.js', '.jsx', '.es6.js'],
13 }
14 ```
15(This relies on the [/lib/generators/resolvers/NPMAndModulesResolver](https://github.com/schwers/r-build/blob/master/lib/generators/resolver/NPMAndModulesResolver.js) and the configuration syntax defined in [/lib/generators/tryToLoadGenerator](https://github.com/schwers/r-build/blob/master/lib/generators/tryToLoadGenerator.js)
16* raw webpack objects. in any section of a webpack config, you can pass in an object that won't be resolved and used directly. you can also add keys to the webpack config for parameters not handled by the current build system and they'll automatically get passed to webpack:
17
18 ```javascript
19 /* To add autoprefixing to the default configs, you would define a blueprints.config.js in your root directory and write: */
20 var autoprefixer = require('autoprefixer');
21 module.exports = {
22 extensions: true
23 webpack: {
24 postcss: [
25 autoprefixer({
26 browsers: ['last 2 versions'],
27 }),
28 ],
29 }
30 };
31 ```
32
33### Configs
34See [/lib/build/makeBuild](https://github.com/schwers/r-build/blob/master/lib/makeBuild.js) and [/bin/buildBlueprints.js](https://github.com/schwers/r-build/blob/master/bin/buildBlueprints.js) To understand more how builds work.
35
36In practice, say you have a simple client you want to build with less, css, es6/7, and you want it to watch. you would run `buildBlueprints -c -w`, or you could define your own (in this case equivalent) config in a `blueprints.config.js` with the contents:
37
38```javascript
39module.exports = [{
40 name: 'Client',
41 webpack: {
42 entry: './lib/Client.es6.js',
43 output: {
44 generator: 'simple',
45 dest: './bin',
46 },
47 resolve: {
48 generator: 'npm-and-modules',
49 extensions: ['', '.js', '.jsx', 'es6.js', '.json'],
50 },
51 loaders: [
52 'esnextreact',
53 'json',
54 'css',
55 'less',
56 ],
57 plugins: [
58 'extract-css',
59 'abort-if-errors',
60 ],
61 },
62}];
63```
64
65## Future goals
66* automatically managing of peer-depedencies for smaller builds. Right now there's tree shaking and you can target UMD, but it'd be nice to see how far we can take the optimizations.
67* Self-hosting: build build with build, check in a compiled copy, which would be the in `/bin` and then write new developments of build in es6/7