-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
40 lines (35 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict'
var RSVP = require('rsvp')
var path = require('path')
var webpack = require('webpack')
var CachingWriter = require('broccoli-caching-writer')
WebpackWriter.prototype = Object.create(CachingWriter.prototype)
WebpackWriter.prototype.constructor = WebpackWriter
function WebpackWriter (inputNodes, options) {
options = options || {}
CachingWriter.call(this, inputNodes, {
annotation: options.annotation
})
this.options = options
}
WebpackWriter.prototype.build = function () {
return RSVP.all(this.inputPaths.map(function (srcDir) {
this.options.context = path.resolve(srcDir)
this.options.output = this.options.output || {}
this.options.output.path = this.outputPath
var compiler = webpack(this.options)
return new RSVP.Promise(function (resolve, reject) {
compiler.run(function (err, stats) {
var jsonStats = stats.toJson()
if (jsonStats.errors.length > 0) jsonStats.errors.forEach(console.error)
if (jsonStats.warnings.length > 0) jsonStats.warnings.forEach(console.warn)
if (err || jsonStats.errors.length > 0) {
reject(err)
} else {
resolve()
}
})
})
}.bind(this)))
}
module.exports = WebpackWriter