-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
165 lines (138 loc) · 4.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
'use strict';
var project = require('./package.json');
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var DIR_BUILD_BASE = 'dist/';
var DIR_BUILD_SCRIPTS = DIR_BUILD_BASE + 'scripts/';
var DIR_BUILD_STYLES = DIR_BUILD_BASE + 'styles/';
var UMD_CONFIG = {
namespace: function() {
return project.title;
},
exports: function() {
return project.title;
}
};
function processStyles (src) {
return function () {
return gulp.src(src)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10,
includePaths: ['.'],
onError: console.error.bind(console, 'Sass error:')
}))
.pipe(plugins.postcss([
require('autoprefixer-core')({
browsers: ['last 1 version']
})
]))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest('.tmp/styles'))
.pipe(reload({
stream: true
}));
};
}
gulp.task('styles', processStyles('src/styles/main.scss'));
gulp.task('styles-demo', processStyles('demo/styles/demo.scss'));
gulp.task('jshint', function() {
return gulp.src('app/scripts/**/*.js')
.pipe(reload({
stream: true,
once: true
}))
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.if(!browserSync.active, plugins.jshint.reporter('fail')));
});
gulp.task('html', ['styles'], function() {
var assets = plugins.useref.assets({
searchPath: ['.tmp', '.']
});
return gulp.src('demo/*.html')
.pipe(assets)
.pipe(plugins.if('*.js', plugins.uglify()))
.pipe(plugins.if('*.css', plugins.csso()))
.pipe(assets.restore())
.pipe(plugins.useref())
.pipe(plugins.if('*.html', plugins.minifyHtml({
conditionals: true,
loose: true
})))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', require('del').bind(null, ['.tmp', 'dist']));
gulp.task('serve', ['styles', 'styles-demo'], function() {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'src', 'demo'],
routes: {
'/bower_components': 'bower_components'
}
}
});
// watch for changes
gulp.watch([
'demo/*.html',
'src/scripts/**/*.js'
]).on('change', reload);
gulp.watch([
'src/styles/**/*.scss',
], ['styles']);
gulp.watch([
'demo/styles/**/*.scss'
], ['styles-demo']);
});
gulp.task('build:vanilla', ['jshint'], function() {
return gulp.src('src/scripts/main.js')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.umd(UMD_CONFIG))
.pipe(plugins.header(';(function(document, undefined) {\n'))
.pipe(plugins.footer('})(window.document);'))
.pipe(plugins.rename({ basename: project.name }))
.pipe(plugins.size({ showFiles: true }))
.pipe(gulp.dest(DIR_BUILD_SCRIPTS))
.pipe(plugins.uglify())
.pipe(plugins.rename({ extname: '.min.js' }))
.pipe(plugins.size({ showFiles: true }))
.pipe(plugins.sourcemaps.write('../maps'))
.pipe(gulp.dest(DIR_BUILD_SCRIPTS));
});
gulp.task('build:jquery', ['jshint'], function() {
return gulp.src(['src/scripts/main.js', 'src/scripts/jquery-plugin.js'])
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat(project.name + '.jquery.js'))
.pipe(plugins.umd(UMD_CONFIG))
.pipe(plugins.header(';(function($, document, undefined) {\n'))
.pipe(plugins.footer('})(jQuery, window.document);'))
.pipe(plugins.size({ showFiles: true }))
.pipe(gulp.dest(DIR_BUILD_SCRIPTS))
.pipe(plugins.uglify())
.pipe(plugins.rename({ extname: '.min.js' }))
.pipe(plugins.size({ showFiles: true }))
.pipe(plugins.sourcemaps.write('../maps'))
.pipe(gulp.dest(DIR_BUILD_SCRIPTS));
});
gulp.task('build:styles', ['styles'], function() {
return gulp.src(['.tmp/styles/main.css'])
.pipe(plugins.rename({ basename: project.name }))
.pipe(gulp.dest(DIR_BUILD_STYLES))
.pipe(plugins.csso())
.pipe(plugins.rename({ extname: '.min.css' }))
.pipe(gulp.dest(DIR_BUILD_STYLES));
});
gulp.task('build', ['build:vanilla', 'build:jquery', 'build:styles'], function() {
return gulp.src(DIR_BUILD_BASE + '**/*').pipe(plugins.size({
title: 'build',
gzip: true
}));
});
gulp.task('default', ['clean'], function() {
gulp.start('build');
});