UNPKG

1.1 kBJavaScriptView Raw
1var _ = require('lodash');
2var serialize = require('serialize-javascript');
3
4var Compiler = require('./Compiler');
5var Cache = require('./plugins/Cache');
6var Clean = require('./plugins/Clean');
7var LiveReload = require('./plugins/LiveReload');
8var Log = require('./plugins/Log');
9var convertOptions = require('./convertOptions');
10
11module.exports = function(options, callback) {
12 options = convertOptions(options);
13
14 var compiler = new Compiler(options);
15
16 var plugins = options.plugins || [];
17
18 options.cache && plugins.unshift(
19 new Cache(
20 serialize(_.pick(options, ['output', 'cache', 'hashLength', 'hashConnector', 'domain', 'plugins', 'modules', 'resolve'])),
21 options.cache,
22 options.context,
23 options.output
24 )
25 );
26 plugins.push(new Clean());
27 plugins.push(new Log(options.output));
28 options.watch && plugins.push(new LiveReload());
29
30 plugins.forEach(function(plugin) {
31 compiler.apply(plugin);
32 });
33
34 if (callback) {
35 if (options.watch) {
36 compiler.watch(callback);
37 } else {
38 compiler.run(callback);
39 }
40 }
41
42 return compiler;
43};