-
Notifications
You must be signed in to change notification settings - Fork 15
/
taskfile.js
121 lines (110 loc) · 3.32 KB
/
taskfile.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const browserSync = require('browser-sync');
let isWatching = false;
// some source/dest consts
const target = 'dist';
const releaseTarget = 'release';
const src = {
js: 'src/**/*.js',
scss: 'src/styles/app.scss',
staticAssets: ['src/static/**/*.*', 'src/*.html'],
vendor: []
};
export async function clean(taskr) {
await taskr.clear([target, releaseTarget]);
}
export async function copyStaticAssets(taskr, o) {
await taskr.source(o.src || src.staticAssets).target(target);
}
export async function vendors(taskr) {
await taskr
.source(src.vendor)
.concat('vendor.js')
.target(`${target}`);
}
export async function js(taskr) {
await taskr
.source('src/app.js')
.rollup({
rollup: {
plugins: [
require('rollup-plugin-buble')({ jsx: 'h' }),
require('rollup-plugin-commonjs')(),
require('rollup-plugin-replace')({
'process.env.NODE_ENV': JSON.stringify(isWatching ? 'development' : 'production')
}),
require('rollup-plugin-node-resolve')({
browser: true,
main: true
})
]
},
bundle: {
format: 'iife',
sourceMap: isWatching,
moduleName: 'window'
}
})
.target(`${target}`);
}
export async function styles(taskr) {
await taskr
.source(src.scss)
.sass({
outputStyle: 'compressed',
includePaths: []
})
.postcss({ plugins: [require('autoprefixer')({ browsers: ['last 2 versions'] })] })
.target(`${target}`);
}
export async function build(taskr) {
// TODO add linting
await taskr.serial(['clean', 'copyStaticAssets', 'styles', 'js', 'vendors']);
}
export async function release(taskr) {
await taskr
.source(`${target}/*.js`)
.uglify({
compress: {
conditionals: 1,
drop_console: 1,
comparisons: 1,
join_vars: 1,
booleans: 1,
loops: 1
}
})
.target(target);
await taskr
.source(`${target}/**/*`)
.rev({
ignores: ['.html', '.png', '.svg', '.ico', '.json', '.txt']
})
.revManifest({ dest: releaseTarget, trim: target })
.revReplace()
.target(releaseTarget);
await taskr
.source(`${releaseTarget}/*.html`)
.htmlmin()
.target(releaseTarget);
await taskr
.source(`${releaseTarget}/**/*.{js,css,html,png,jpg,gif}`)
.precache({ stripPrefix: `${releaseTarget}/` })
.target(releaseTarget);
}
export async function watch(taskr) {
isWatching = true;
await taskr.start('build');
await taskr.watch(src.js, ['js', 'reload']);
await taskr.watch(src.scss, ['styles', 'reload']);
await taskr.watch(src.staticAssets, ['copyStaticAssets', 'reload']);
// start server
browserSync({
server: target,
logPrefix: 'hyperapp',
port: process.env.PORT || 4000,
middleware: [require('connect-history-api-fallback')()]
});
}
export async function reload(taskr) {
isWatching && browserSync.reload();
}