-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
175 lines (152 loc) · 3.79 KB
/
gulpfile.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
'use strict';
var gulp = require('gulp');
var riot = require('gulp-riot');
var plugins = require('gulp-load-plugins')();
var rimraf = require('rimraf');
var browserSync = require('browser-sync');
var runSequence = require('run-sequence');
var karma = require('karma').server;
// DEVELOPMENT TASKS
//================================================
/*
* 1. Setup a webserver with livereload using BrowserSync
* 2. JS and CSS get processed and served from the 'build' folder
* 3. Riot: Transform riot tag files and put in build 'build' folder
* 4. Compile sass files, autoprefix and put in 'build' folder
* */
// BrowserSync Server
gulp.task('browser-sync', function() {
browserSync.init([
'./build/css/*.css',
'./build/js/**/*.js',
'./**/*.html'
],
{
notify: false,
server: {
baseDir: ['./']
},
port: 3500,
browser: [],
tunnel: false
});
});
// Riot
gulp.task('riot', function() {
return gulp.src('src/**/*.tag')
//.pipe(plugins.cached('tag')) //Process only changed files
.pipe(riot())
.pipe(gulp.dest('build/'));
});
// JS
gulp.task('js', function() {
return gulp.src('src/**/*.js')
//.pipe(plugins.cached('tag')) //Process only changed files
.pipe(gulp.dest('build/'));
});
// Sass
gulp.task('sass', function() {
return gulp.src('./src/sass/main.scss')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass())
.pipe(plugins.sourcemaps.write({includeContent: false}))
.pipe(plugins.sourcemaps.init({loadMaps: true})) // Load sourcemaps generated by sass
.pipe(plugins.autoprefixer({
browsers: ['last 2 versions']
}))
.on('error', plugins.util.log)
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('./build/css'))
.on('error', plugins.util.log);
});
// serve task
gulp.task('serve', ['browser-sync', 'riot', 'js', 'sass'] , function(cb) {
plugins.watch(
'./src/sass/**/*.scss',
{
name: 'SASS'
},
function() {
gulp.start('sass');
}
);
plugins.watch(
'./src/js/**/*.tag',
{
name: 'TAG'
},
function() {
gulp.start('riot');
}
);
plugins.watch(
'./src/js/**/*.js',
{
name: 'JS'
},
function() {
gulp.start('js');
}
);
});
// Delete build Directory
gulp.task('delete-build', function() {
rimraf('./build', function(err) {
plugins.util.log(err);
});
});
//build (no server)
gulp.task('build', ['riot', 'sass']);
// Default
gulp.task('default', ['serve']);
// Tests
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
}, done);
});
// DISTRIBUTION TASKS
//===============================================
// Delete dist Directory
gulp.task('delete-dist', function() {
rimraf('./dist', function(err) {
plugins.util.log(err);
});
});
// CSS
gulp.task('css', function() {
return gulp.src('./build/css/main.css')
.pipe(gulp.dest('./dist/css'))
.pipe(plugins.csso())
.pipe(plugins.rename('main.min.css'))
.pipe(gulp.dest('./dist/css'))
.on('error', plugins.util.log);
});
// Copy index.html to 'dist'
gulp.task('html', function() {
gulp.src(['./index.html'])
.pipe(gulp.dest('./dist'))
.on('error', plugins.util.log);
});
// Bundle with jspm
gulp.task('bundle', ['riot', 'js'], plugins.shell.task([
'jspm bundle-sfx build/js/main dist/js/app.js'
]));
// Uglify the bundle
gulp.task('uglify', function() {
return gulp.src('./dist/js/app.js')
.pipe(plugins.sourcemaps.init({loadMaps: true}))
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write('.'))
.pipe(plugins.rename('app.min.js'))
.pipe(gulp.dest('./dist/js'))
.on('error', plugins.util.log);
});
gulp.task('dist', function() {
runSequence(
'delete-dist',
'build',
['css', 'html', 'bundle'],
'uglify'
);
});