-
Notifications
You must be signed in to change notification settings - Fork 27
/
build.js
48 lines (41 loc) · 1.26 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
var fs = require('fs');
var babel = require('rollup-plugin-babel');
var rollup = require('rollup');
var uglify = require('uglify-js');
var args = process.argv;
var packageFile = JSON.parse(fs.readFileSync('package.json', 'utf8'));
var version = packageFile.version;
var files = {
src: './src/stickyElements.js',
srcAnimate: './node_modules/animateplus/animate.min.js',
dist: './dist/stickyelements.js',
distAnimate: './dist/stickyelements-animate.js'
}
function minify (code) {
return uglify.minify(code, {fromString: true}).code;
}
function runBuild () {
fs.mkdir('./dist', (err) => {
rollup.rollup({
entry: files.src,
plugins: [ babel({presets: [ 'es2015-rollup' ]}) ]
}).then(function (bundle) {
var result = bundle.generate({
format: 'iife',
moduleName: 'stickyElements'
});
var code = minify(result.code);
fs.writeFile(files.dist, code, 'utf8');
fs.readFile(files.srcAnimate, 'utf8', (err, animate) => {
fs.writeFile(files.distAnimate, animate + code, 'utf8');
});
}, function (err) {
console.log(err);
});
});
}
runBuild();
if (args[2] && args[2] === '-w') {
fs.watchFile(files.src, runBuild);
fs.watchFile('./src/StickyElement.js', runBuild);
}