UNPKG

5.07 kBMarkdownView Raw
1Baconize
2========
3
4[![npm version](https://badge.fury.io/js/baconize.svg)](https://badge.fury.io/js/baconize)
5[![Build Status](https://travis-ci.org/davej/baconize.svg?branch=master)](https://travis-ci.org/davej/baconize)
6
7Compile/minify static site for production (with sourcemaps), auto-compiles files like `app.coffee -> app.js`.
8
9Currently supports: `LiveScript`, `babel`, `coco`, `coffee-script`, `dogescript`, `less`, `marked`, `myth`, `jade`, `node-sass`, `stylus`, `swig`. To use any of these you must do `npm install x` as needed (where `x` is the name of the lib), baconize does not install them by default.
10
11Example
12-------
13
14```javascript
15var baconize = require('baconize');
16
17var source = '/path/to/input/dir';
18var target = '/path/to/output/dir';
19baconize(source, target, [options]).then([successFn],[errorFn]);
20```
21
22How it works:
23 * Baconize will walk your source directory and process each file in `/path/to/input/dir`:
24 * If it can compile a file then it will compile it and output it to the target directory (with source map).
25 * If it *can't* compile the file then it will simply copy it to the target.
26
27For example, if you have a coffeescript file in `/path/to/input/dir/my-app/scripts/index.coffee` then it will output the compiled file as `/path/to/output/dir/my-app/scripts/index.js`, and the sourcemap as `/path/to/output/dir/my-app/scripts/index.js.map`.
28
29This library is designed for use alongside [pingy-in-the-middle](https://github.com/davej/piggy-in-the-middle).
30
31
32Options
33-------
34
35- **compile** (Boolean, default = true): should baconize try to compile files where possible?
36
37- **sourcemaps** (Boolean, default = true): should baconize copy corresponding sourcemaps and source files for the minified/compiled files?
38
39- **minify** (Boolean, default = false): should baconize minify javascript, css and html files? Will also minify post-compilation files.
40
41- **blacklist** (Array): filter to blacklist files from being compiled or minifed. They will still be copied (without compilation/minifiction) unless they are negated using the `fileFilter` or `directoryFilter` options below. This option is useful for vendor directories (like 'bower_components') which already include the compiled versions of files. See [Filters](#filters) for more.
42
43- **fileFilter** (Array): filter to include/exclude files to be copied to target. See [Filters](#filters) for more.
44
45- **directoryFilter** (Array): filter to include/exclude directories to be copied to target, rules are applied to sub-directories also. Useful for directories like '.git'. See [Filters](#filters) for more.
46
47- **depth** (Number): depth at which to stop recursing even if more subdirectories are found.
48
49- **exclusions** (Object): Instead of `blacklist`, `fileFilter` and `directoryFilter` you can use the new exclusions api, this is undocumented for the moment.
50
51
52Filters
53-------
54
55Filters take an array of glob strings. `fileFilter` and `directoryFilter` can be a whitelist or blacklist, by default they are whitelist but add the `!` character before entries to turn them into a blacklist instead:
56
57* `compileBlacklist: [ 'bower_components/**' ]` copies the raw 'bower_components' directory instead of compiling files within the directory.
58
59* `fileFilter: [ '*.json', '*.js', '*.scss', '*.jade' ]` includes *only* JavaScript, JSON, SCSS and Jade files.
60
61* `directoryFilter: [ '!.git', '!node_modules' ]` includes all directories *except* '.git' and 'node_modules'.
62
63See [minimatch](https://github.com/isaacs/minimatch) for some examples of glob strings.
64
65
66Events
67------
68
69You can listen to `chdir` and `compile-start` and `compile-finised` events emitted by baconize.
70```javascript
71var bacon = baconize(source, target, [options]);
72
73bacon.on('chdir', function(folder) {
74 // `folder` (string) is the current folder path that is being processed by baconize
75});
76
77bacon.on('compile-start', function(file) {
78 // compile has started on `file` (object).
79 //
80 // {
81 // name: 'typography.css',
82 // path: 'styles/typography.css',
83 // fullPath: '/Users/dave/Sites/my-site/styles/typography.css',
84 // parentDir: 'styles',
85 // fullParentDir: '/Users/dave/Sites/my-site/styles/',
86 // stat: {object} See: https://nodejs.org/api/fs.html#fs_class_fs_stats
87 // }
88});
89
90bacon.on('compile-done', function(file) {
91 // compile has finished successfully on `file` (object, see above).
92});
93```
94
95Aborting while in progress
96--------------------------
97
98You can abort baconize while it's in progress.
99If you do this then the promise will reject and the output directory will be removed.
100
101```javascript
102var bacon = baconize(source, target, [options]);
103
104// abort baconize while in progress
105setTimeout(function() { bacon.abort(); }, 10);
106
107bacon.then(function(){}, function(err) {
108 // err (Error)
109 // {
110 // message: 'Manually aborted by user',
111 // code: 'ABORT'
112 // }
113})
114```
115
116Try it out
117----------
118The easiest way to try this out is to `clone` the repo, `cd` into it and do:
119
120```sh
121npm install
122npm run example
123```
124
125This will compile a basic demo site to `examples/output`.