-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
170 lines (149 loc) · 4.27 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
var gulp = require('gulp');
var path = require('path');
var $ = require('gulp-load-plugins')();
var del = require('del');
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var wiredep = require('wiredep').stream;
var inject = require('gulp-inject');
var filter = require('gulp-filter');
var concat = require('gulp-concat');
var mainBowerFiles = require('main-bower-files');
var csso = require('gulp-csso');
var environment = $.util.env.type || 'development';
var isProduction = environment === 'production';
var webpackConfig = require('./webpack.config.js')[environment];
var port = $.util.env.port || 1337;
var src = 'src/';
var dist = 'dist/';
var autoprefixerBrowsers = [
'ie >= 9',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 6',
'opera >= 23',
'ios >= 6',
'android >= 4.4',
'bb >= 10'
];
// ... variables
var sassOptions = {
errLogToConsole: true,
outputStyle: 'expanded'
};
/*
gulp.task('libstyles', function(){
var injectAppFiles = gulp.src('src/*.scss', {read: false});
function transformFilepath(filepath) {
return '@import "' + filepath + '";';
}
var injectAppOptions = {
transform: transformFilepath,
starttag: '// inject:app',
endtag: '// endinject',
addRootSlash: false
};
return gulp.src('src/main.scss')
.pipe(wiredep())
.pipe(inject(injectAppFiles, injectAppOptions))
.pipe(sass())
.pipe(gulp.dest('dist/styles'));
});
*/
gulp.task('sass', function () {
var injectAppFiles = gulp.src('src/*.scss', {read: false});
var injectGlobalFiles = gulp.src('src/global/*.scss', {read: false});
function transformFilepath(filepath) {
return '@import "' + filepath + '";';
}
var injectAppOptions = {
transform: transformFilepath,
starttag: '// inject:app',
endtag: '// endinject',
addRootSlash: false
};
var injectGlobalOptions = {
transform: transformFilepath,
starttag: '// inject:global',
endtag: '// endinject',
addRootSlash: false
};
return gulp
.src(src + 'styles/*.scss')
.pipe(sourcemaps.init())
.pipe(wiredep())
.pipe(inject(injectGlobalFiles, injectGlobalOptions))
.pipe(inject(injectAppFiles, injectAppOptions))
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe($.autoprefixer({browsers: autoprefixerBrowsers}))
.pipe(sourcemaps.write())
.pipe(csso())
.pipe(gulp.dest(dist + 'css/'))
.pipe($.size({ title : 'css' }))
.pipe($.connect.reload());
});
gulp.task('vendors', function(){
return gulp.src(mainBowerFiles())
.pipe(filter('*.css'))
.pipe(concat('vendors.css'))
.pipe(csso())
.pipe(gulp.dest(dist + 'css/'));
});
gulp.task('scripts', function() {
return gulp.src(webpackConfig.entry)
.pipe($.webpack(webpackConfig))
.pipe(isProduction ? $.uglifyjs() : $.util.noop())
.pipe(gulp.dest(dist + 'js/'))
.pipe($.size({ title : 'js' }))
.pipe($.connect.reload());
});
gulp.task('html', function() {
return gulp.src(src + 'index.html')
.pipe(gulp.dest(dist))
.pipe($.size({ title : 'html' }))
.pipe($.connect.reload());
});
/*
gulp.task('styles',function(cb) {
return gulp.src(src + 'stylus/main.styl')
.pipe($.stylus({
compress: isProduction,
'include css' : true
}))
.pipe($.autoprefixer({browsers: autoprefixerBrowsers}))
.pipe(gulp.dest(dist + 'css/'))
.pipe($.size({ title : 'css' }))
.pipe($.connect.reload());
});
*/
gulp.task('serve', function() {
$.connect.server({
root: dist,
port: port,
livereload: {
port: 35728
}
});
});
gulp.task('static', function(cb) {
return gulp.src(src + 'static/**/*')
.pipe($.size({ title : 'static' }))
.pipe(gulp.dest(dist + 'static/'));
});
gulp.task('watch', function() {
//gulp.watch(src + 'stylus/*.styl', ['styles']);
gulp.watch(src + 'styles/*.scss', ['sass']);
gulp.watch(src + 'index.html', ['html']);
gulp.watch(src + 'app/**/*.js', ['scripts']);
});
gulp.task('clean', function(cb) {
del([dist], cb);
});
// by default build project and then watch files in order to trigger livereload
gulp.task('default', ['build', 'serve', 'watch']);
// waits until clean is finished then builds the project
gulp.task('build', ['clean'], function(){
gulp.start(['static', 'html','scripts','sass', 'vendors']);
});