forked from vuejs/vueify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.14 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
41
42
43
44
45
46
47
48
49
50
51
52
53
var through = require('through')
var compiler = require('./lib/compiler')
module.exports = function vueify (file, options) {
if (!/.vue$/.test(file)) {
return through()
}
compiler.loadConfig()
compiler.applyConfig(options)
compiler.applyConfig({
sourceMap: options._flags.debug
})
var data = ''
var stream = through(write, end)
stream.vueify = true
function dependency (file) {
stream.emit('file', file)
}
function emitStyle (e) {
stream.emit('vueify-style', e)
}
function write (buf) {
data += buf
}
function end () {
stream.emit('file', file)
compiler.on('dependency', dependency)
compiler.on('style', emitStyle)
compiler.compile(data, file, function (error, result) {
compiler.removeListener('dependency', dependency)
compiler.removeListener('style', emitStyle)
if (error) {
stream.emit('error', error)
// browserify doesn't log the stack by default...
console.error(error.stack.replace(/^.*?\n/, ''))
}
stream.queue(result)
stream.queue(null)
})
}
return stream
}
// expose compiler
module.exports.compiler = compiler