-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.js
56 lines (44 loc) · 1.31 KB
/
build.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
54
55
56
const fs = require('fs');
const path = require('path');
const browserify = require('browserify');
const exorcist = require('exorcist');
const srcDir = __dirname;
const outputDir = path.join(__dirname, 'dist');
const outputProd = path.join(outputDir, 'devicehive.min.js');
const outputDev = path.join(outputDir, 'devicehive.js');
const mapDev = path.join(outputDir, 'devicehive.js.map');
const bundlerProd = browserify(path.join(srcDir, 'index-browser.js'));
const bundlerDev = browserify(path.join(srcDir, 'index-browser.js'), {
debug: true
});
const encoding = 'utf8';
// Creating dist directory
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
// preset
bundlerProd
.transform('babelify')
.plugin('tinyify', {
flat: false,
uglifyOpts: {
global: true,
sourceMap: true
}
});
bundlerDev
.transform('babelify');
bundlerDev
.transform('babelify');
// build
bundlerProd.bundle()
.pipe(fs.createWriteStream(outputProd), encoding)
.on('finish', () => {
console.log('\x1b[36m%s\x1b[0m', 'Production build complete!');
});
bundlerDev.bundle()
.pipe(exorcist(mapDev))
.pipe(fs.createWriteStream(outputDev), encoding)
.on('finish', () => {
console.log('\x1b[36m%s\x1b[0m', 'Development build complete!');
});