-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflyfile.js
87 lines (75 loc) · 2.06 KB
/
flyfile.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
const bs = require('browser-sync');
const cRoll = require('./config/rollup');
const cUgly = require('./config/uglify');
let isWatch = 0;
const tar = 'dist';
const rel = 'release';
const node = 'node_modules';
const src = {
js: 'src/scripts/**',
css: 'src/styles/**',
copy: [
'src/static/**/*.*',
'src/*.html'
],
vendor: [
// js vendors to be merged as `vendor.js`
`${node}/promise-polyfill/promise.min.js`
]
};
export async function clean(fly) {
await fly.clear([tar, rel]);
}
export async function copies(fly, o) {
await fly.source(o.src || src.copy).target(tar);
}
let conf;
export async function scripts(fly) {
conf = conf || cRoll(isWatch && 'development');
await fly.source('src/scripts/app.js').xo().rollup(conf).target(`${tar}/js`);
}
export async function vendors(fly) {
await fly.source(src.vendor).concat('vendor.js').target(`${tar}/js`);
}
export async function styles(fly) {
await fly.source('src/styles/app.sass').sass({
includePaths: [`${node}/md-colors/src`],
outputStyle: 'compressed'
}).autoprefixer().target(`${tar}/css`);
}
export async function build(fly) {
await fly.parallel(['clean', 'copies', 'vendors', 'scripts', 'styles']);
}
export async function release(fly) {
// minify js
await fly.source(`${tar}/js/*`).uglify(cUgly).target(`${tar}/js`);
// version assets
await fly.source(`${tar}/**/*`).rev({
ignores: ['.html', '.png', '.svg', '.ico', '.json', '.txt']
}).revManifest({dest: rel, trim: tar}).revReplace().target(rel);
// make assets available for offline
await fly.source(`${rel}/**/*`).precache({
navigateFallback: 'index.html',
stripPrefix: rel
}).target(rel);
}
export async function watch(fly) {
isWatch = 1;
await fly.start('build');
await fly.watch(src.js, ['scripts', 'reload']);
await fly.watch(src.css, ['styles', 'reload']);
await fly.watch(src.copy, ['copies', 'reload']);
// start server
bs({
server: tar,
logPrefix: 'Fly',
port: process.env.PORT || 3000,
middleware: [
require('connect-history-api-fallback')()
]
});
}
export async function reload() {
isWatch && bs.reload();
}