-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
80 lines (71 loc) · 1.68 KB
/
Copy pathbuild.js
File metadata and controls
80 lines (71 loc) · 1.68 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var reduce = require('reduce-css')
var del = require('del')
var path = require('path')
var Transform = require('stream').Transform
var basedir = path.join(__dirname, 'src')
var i = process.argv.indexOf('-w')
if (i === -1) {
i = process.argv.indexOf('--watch')
}
var needWatch = i > -1
if (needWatch) {
var b = createBundler(true)
b.on('update', function update() {
bundle(b)
return update
}())
} else {
bundle(createBundler())
}
function createBundler(watch) {
var basedir = path.join(__dirname, 'src')
var b = reduce.create(
/* glob for entries */
'*.css',
/* options for depsify */
{
basedir,
cache: {},
packageCache: {},
},
/* options for common-bundle */
// single bundle
// 'bundle.css',
// multiple bundles
{
groups: '*.css',
common: 'common.css',
},
/* options for watchify2 */
watch && { entryGlob: '*.css' }
)
return b
}
function bundle(b) {
var startTime = Date.now()
log('Start bundling')
var build = path.join(__dirname, 'build')
del.sync(build)
return b.bundle().on('error', log)
.pipe(Transform({
objectMode: true,
transform: function (file, enc, next) {
log('-', file.relative, file.contents.length, 'bytes')
next(null, file)
}
}))
.pipe(b.dest(build, {
maxSize: 0,
name: '[name].[hash]',
assetOutFolder: path.join(build, 'assets'),
}))
.on('end', () => log('End bundling in', Date.now() - startTime, 'ms'))
}
function log() {
console.log.apply(console, [].map.call(arguments, function (msg) {
if (typeof msg === 'string') {
return msg
}
return JSON.stringify(msg, null, 2)
}))
}