UNPKG

1.31 kBMarkdownView Raw
1# Auton - automated resource compiler
2
3(for a quick start, see example/example.js. The code below is a simple example of how to define your own rules / chains)
4
5this is very rudimentary and i'd like a more complicated example in here.
6
7```javascript
8var auton = require('./lib/auton'),
9 Compiler = auton.Compiler,
10 plugins = auton.plugins,
11 path = require('path');
12
13var compiler = new Compiler('build', 'htdocs', true); // true is whether or not watch mode is on
14
15compiler.addRule(
16 /.js$/,
17 javascriptSave,
18 [plugins.read, plugins.jshint, plugins.uglify, plugins.gzip, plugins.save]
19);
20
21compiler.start();
22
23
24// decide what the filename of saved files should be
25function javascriptSave(type, filePath) {
26 var filename = path.basename(filePath, '.js'),
27 dirname = path.dirname(filePath),
28 output = dirname + "/" + filename;
29
30 if (type === 'minified') {
31 return output + ".min.js";
32 }
33 else if (type === 'compressed') {
34 return output + ".min.js.gz";
35 }
36 else if (type === 'plain' || type === '__age_check__') {
37 return output + ".js";
38 }
39 else {
40 return null;
41 }
42}
43```
44
45this example will find all files ending with .js within the folder 'build', run them through jshint, uglify-js, and gzip, and save a non-minified, a minified, and a minified+gzipped version.